forked from fabiodalez-dev/Pinakes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbook_form.php
More file actions
4944 lines (4483 loc) · 226 KB
/
Copy pathbook_form.php
File metadata and controls
4944 lines (4483 loc) · 226 KB
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
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/** @var ?bool $libraryThingInstalled */
use App\Support\Hooks;
use App\Support\HtmlHelper;
$mode = $mode ?? 'create';
$book = $book ?? [];
$csrfToken = $csrfToken ?? null;
$error_message = $error_message ?? null;
$action = $action ?? url($mode === 'edit' ? '/admin/books/update/' . (int)($book['id'] ?? 0) : '/admin/books/create');
$currentCover = $book['copertina_url'] ?? ($book['copertina'] ?? '');
$scrapingAvailable = Hooks::has('scrape.fetch.custom');
$scaffali = $scaffali ?? [];
$mensole = $mensole ?? [];
$libraryThingInstalled = $libraryThingInstalled ?? false;
$initialAuthors = array_map(static function ($author) {
return [
'id' => (int)($author['id'] ?? 0),
// Pseudonym-aware label (issue #237): "Pseudonimo (Nome)" when set.
'label' => \App\Support\AuthorName::display($author)
];
}, $book['autori'] ?? []);
// Contributor roles (issue #237): illustrator/translator/curator/colorist are
// entity pickers just like authors. Initial selections mirror the authors shape.
$contributorRoleKeys = ['illustratori', 'traduttori', 'curatori', 'coloristi'];
$initialContributors = [];
foreach ($contributorRoleKeys as $roleKey) {
$initialContributors[$roleKey] = array_map(static function ($c) {
return ['id' => (int)($c['id'] ?? 0), 'label' => \App\Support\AuthorName::display($c)];
}, $book[$roleKey] ?? []);
}
// Multi-publisher (issue #143): mirror the authors initial-selection shape.
// Falls back to the single primary publisher for books saved before #143.
$initialPublishers = array_map(static function ($publisher) {
return [
'id' => (int)($publisher['id'] ?? 0),
'label' => $publisher['nome'] ?? ''
];
}, $book['editori'] ?? []);
if ($initialPublishers === [] && !empty($book['editore_id']) && !empty($book['editore_nome'])) {
$initialPublishers[] = ['id' => (int)$book['editore_id'], 'label' => (string)$book['editore_nome']];
}
$initialMensolaId = (int)($book['mensola_id'] ?? 0);
$initialPosizioneProgressiva = (int)($book['posizione_progressiva'] ?? 0);
$initialCollocazione = $book['collocazione'] ?? '';
$initialData = [
'id' => (int)($book['id'] ?? 0),
'radice_id' => (int)($book['radice_id'] ?? 0),
'genere_id' => (int)(($book['resolved_genere_id'] ?? null) ?: ($book['genere_id'] ?? 0)),
'sottogenere_id' => (int)(($book['resolved_sottogenere_id'] ?? null) ?: ($book['sottogenere_id'] ?? 0)),
'classificazione_dewey' => $book['classificazione_dewey'] ?? '',
'editore_id' => (int)($book['editore_id'] ?? 0),
'editore_nome' => $book['editore_nome'] ?? '',
'scaffale_id' => (int)($book['scaffale_id'] ?? 0),
'mensola_id' => $initialMensolaId,
'posizione_progressiva' => $initialPosizioneProgressiva,
'collocazione' => $initialCollocazione,
'stato' => $book['stato'] ?? '',
'tipo_acquisizione' => $book['tipo_acquisizione'] ?? '',
'data_acquisizione' => $book['data_acquisizione'] ?? date('Y-m-d'),
'prezzo' => $book['prezzo'] ?? '',
'peso' => $book['peso'] ?? '',
'numero_pagine' => $book['numero_pagine'] ?? '',
'numero_inventario' => $book['numero_inventario'] ?? '',
'gruppo_serie' => $book['gruppo_serie'] ?? '',
'serie_padre' => $book['serie_padre'] ?? '',
'tipo_collana' => $book['tipo_collana'] ?? 'serie',
'collana' => $book['collana'] ?? '',
'altre_collane' => $book['altre_collane'] ?? '',
'ciclo_serie' => $book['ciclo_serie'] ?? '',
'ordine_ciclo' => $book['ordine_ciclo'] ?? '',
'numero_serie' => $book['numero_serie'] ?? '',
'note_varie' => $book['note_varie'] ?? '',
'file_url' => $book['file_url'] ?? '',
'audio_url' => $book['audio_url'] ?? '',
'parole_chiave' => $book['parole_chiave'] ?? '',
];
$initialData['autori'] = $initialAuthors;
$initialData['editori'] = $initialPublishers;
foreach ($contributorRoleKeys as $roleKey) {
$initialData[$roleKey] = $initialContributors[$roleKey];
}
$initialData['current_cover'] = $currentCover;
$initialAuthorsJson = htmlspecialchars(json_encode($initialAuthors, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP), ENT_QUOTES, 'UTF-8');
$initialContributorsJson = [];
foreach ($contributorRoleKeys as $roleKey) {
$initialContributorsJson[$roleKey] = htmlspecialchars(json_encode($initialContributors[$roleKey], JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP), ENT_QUOTES, 'UTF-8');
}
$initialPublishersJson = htmlspecialchars(json_encode($initialPublishers, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP), ENT_QUOTES, 'UTF-8');
$initialDataJsonRaw = json_encode($initialData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP);
$modeAttr = htmlspecialchars($mode, ENT_QUOTES, 'UTF-8');
$actionAttr = htmlspecialchars($action, ENT_QUOTES, 'UTF-8');
// i18n-2 (refactor): centralised label map; see App\Support\SeriesLabels.
$seriesTypeOptions = \App\Support\SeriesLabels::types();
// i18n-5: normalize legacy/alias tipo (series, cycle, spinoff, ...) so the
// dropdown preselects the canonical key.
$selectedSeriesType = \App\Support\SeriesLabels::canonical($book['tipo_collana'] ?? 'serie');
?>
<?php if (!empty($error_message)): ?>
<div class="mb-6 p-4 rounded-xl border border-red-200 bg-red-50 text-red-700" role="alert">
<i class="fas fa-exclamation-triangle mr-2"></i>
<?php echo HtmlHelper::e($error_message); ?>
</div>
<?php endif; ?>
<form id="bookForm" novalidate data-mode="<?php echo $modeAttr; ?>" method="post" action="<?php echo $actionAttr; ?>" class="space-y-8" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="<?php echo htmlspecialchars((string)$csrfToken, ENT_QUOTES, 'UTF-8'); ?>">
<!-- Hidden fields for scraped data -->
<input type="hidden" id="scraped_ean" name="scraped_ean" value="">
<input type="hidden" id="scraped_pub_date" name="scraped_pub_date" value="">
<input type="hidden" id="scraped_price" name="scraped_price" value="">
<input type="hidden" id="scraped_format" name="scraped_format" value="">
<input type="hidden" id="scraped_series" name="scraped_series" value="">
<input type="hidden" id="scraped_numero_serie" name="scraped_numero_serie" value="">
<input type="hidden" id="scraped_dimensions" name="scraped_dimensions" value="">
<input type="hidden" id="scraped_pages" name="scraped_pages" value="">
<input type="hidden" id="scraped_publisher" name="scraped_publisher" value="">
<input type="hidden" id="scraped_translator" name="scraped_translator" value="">
<input type="hidden" id="scraped_illustrator" name="scraped_illustrator" value="">
<input type="hidden" id="scraped_cover_url" name="scraped_cover_url" value="">
<input type="hidden" id="copertina_url" name="copertina_url" value="<?php echo HtmlHelper::e($currentCover); ?>">
<input type="hidden" id="remove_cover" name="remove_cover" value="0">
<input type="hidden" id="scraped_tipologia" name="scraped_tipologia" value="">
<input type="hidden" id="scraped_author_bio" name="scraped_author_bio" value="">
<?php if ($scrapingAvailable): ?>
<div class="card mb-8">
<div class="card-header">
<h2 class="text-lg font-semibold text-gray-900 flex items-center gap-2">
<i class="fas fa-barcode text-primary"></i>
<?= __("Importa da ISBN") ?>
</h2>
<p class="text-sm text-gray-600 mt-1"><?= __("Usa i servizi online per precompilare automaticamente i dati del libro") ?></p>
</div>
<div class="card-body">
<div class="form-grid-2">
<div>
<label class="form-label"><?= __("Codice ISBN o EAN") ?></label>
<input id="importIsbn" type="text" class="form-input" placeholder="<?= __('es. 9788842935780') ?>" value="<?php echo htmlspecialchars((string)($book['isbn13'] ?? ($book['ean'] ?? ($book['isbn10'] ?? ''))), ENT_QUOTES, 'UTF-8'); ?>" />
</div>
<div class="flex items-end">
<button type="button" id="btnImportIsbn" class="btn-primary w-full">
<i class="fas fa-download mr-2"></i>
<?= $mode === 'edit' ? __("Aggiorna Dati") : __("Importa Dati") ?>
</button>
</div>
</div>
<!-- Source info panel (shown after successful import) -->
<div id="scrapeSourceInfo" class="hidden mt-4 p-3 bg-gray-50 rounded-lg border border-gray-200">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2 text-sm">
<i class="fas fa-database text-primary"></i>
<span class="text-gray-600"><?= __("Fonte dati:") ?></span>
<span id="scrapeSourceName" class="font-medium text-gray-900"></span>
</div>
<button type="button" id="btnShowAlternatives" class="text-xs text-primary hover:text-primary-dark hover:underline hidden" aria-expanded="false" aria-controls="scrapeAlternativesPanel">
<i class="fas fa-exchange-alt mr-1"></i>
<?= __("Vedi alternative") ?>
</button>
</div>
<div id="scrapeSourcesList" class="mt-2 text-xs text-gray-500 hidden">
<span><?= __("Fonti consultate:") ?></span>
<span id="scrapeSourcesListItems"></span>
</div>
</div>
<!-- Alternatives panel (shown when clicking "Vedi alternative") -->
<div id="scrapeAlternativesPanel" class="hidden mt-4 p-4 bg-blue-50 rounded-lg border border-blue-200">
<div class="flex items-center justify-between mb-3">
<h4 class="text-sm font-semibold text-blue-900 flex items-center gap-2">
<i class="fas fa-layer-group"></i>
<?= __("Dati alternativi disponibili") ?>
</h4>
<button type="button" id="btnCloseAlternatives" class="text-gray-800 hover:text-blue-800" aria-label="<?= __('Chiudi alternative') ?>">
<i class="fas fa-times"></i>
</button>
</div>
<div id="alternativesContent" class="space-y-2 text-sm">
<!-- Populated by JavaScript -->
</div>
</div>
</div>
</div>
<?php endif; ?>
<!-- Basic Information Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-book text-primary"></i>
<?= __("Informazioni Base") ?>
</h2>
</div>
<div class="card-body form-section">
<div class="form-grid-2">
<div>
<label for="titolo" class="form-label">
<?= __("Titolo") ?> <span class="text-red-500">*</span>
</label>
<input id="titolo" name="titolo" type="text" required aria-required="true" class="form-input" placeholder="<?= __('es. La morale anarchica') ?>" value="<?php echo HtmlHelper::e($book['titolo'] ?? ''); ?>" />
</div>
<div>
<label for="sottotitolo" class="form-label"><?= __("Sottotitolo") ?></label>
<input id="sottotitolo" name="sottotitolo" type="text" class="form-input" placeholder="<?= __('Sottotitolo del libro (opzionale)') ?>" value="<?php echo HtmlHelper::e($book['sottotitolo'] ?? ''); ?>" />
</div>
</div>
<div class="form-grid-3">
<div>
<label for="isbn10" class="form-label"><?= __("ISBN 10") ?></label>
<input id="isbn10" name="isbn10" type="text" class="form-input" placeholder="<?= __('es. 8842935786') ?>" value="<?php echo HtmlHelper::e($book['isbn10'] ?? ''); ?>" />
</div>
<div>
<label for="isbn13" class="form-label"><?= __("ISBN 13") ?></label>
<input id="isbn13" name="isbn13" type="text" class="form-input" placeholder="<?= __('es. 9788842935780') ?>" value="<?php echo HtmlHelper::e($book['isbn13'] ?? ''); ?>" />
</div>
<div>
<label for="edizione" class="form-label"><?= __("Edizione") ?></label>
<input id="edizione" name="edizione" type="text" class="form-input" placeholder="<?= __('es. Prima edizione') ?>" value="<?php echo HtmlHelper::e($book['edizione'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("Numero o descrizione dell'edizione") ?></p>
</div>
</div>
<div class="form-grid-2">
<div>
<label for="data_pubblicazione" class="form-label"><?= __("Data di Pubblicazione") ?></label>
<input id="data_pubblicazione" name="data_pubblicazione" type="text" class="form-input" placeholder="<?= __('es. 26 agosto 2025') ?>" value="<?php echo HtmlHelper::e($book['data_pubblicazione'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("Data di pubblicazione originale (testo libero)") ?></p>
</div>
<div>
<label for="anno_pubblicazione" class="form-label"><?= __("Anno di Pubblicazione") ?></label>
<input id="anno_pubblicazione" name="anno_pubblicazione" type="number" min="-9999" max="9999" class="form-input" placeholder="<?= __('es. 2025') ?>" value="<?php echo HtmlHelper::e($book['anno_pubblicazione'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("Anno numerico (usato per filtri e ordinamento)") ?></p>
</div>
</div>
<div class="form-grid-3">
<div>
<label for="ean" class="form-label"><?= __("EAN") ?></label>
<input id="ean" name="ean" type="text" class="form-input" placeholder="<?= __('es. 9788842935780') ?>" value="<?php echo HtmlHelper::e($book['ean'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("European Article Number (opzionale)") ?></p>
</div>
<div>
<label for="issn" class="form-label"><?= __("ISSN") ?></label>
<input id="issn" name="issn" type="text" class="form-input" placeholder="<?= HtmlHelper::e(__('es. 1234-5678')) ?>" value="<?php echo HtmlHelper::e($book['issn'] ?? ''); ?>" pattern="\d{4}-\d{3}[\dXx]" />
<p class="text-xs text-gray-500 mt-1"><?= __("International Standard Serial Number (per periodici)") ?></p>
</div>
<div>
<label for="lingua" class="form-label"><?= __("Lingua") ?></label>
<input id="lingua" name="lingua" type="text" class="form-input" placeholder="<?= __('es. Italiano, Inglese') ?>" value="<?php echo HtmlHelper::e($book['lingua'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("Lingua originale del libro") ?></p>
</div>
</div>
<!-- Authors with Choices.js -->
<div>
<label for="autori_select" class="form-label"><?= __("Autori") ?></label>
<select id="autori_select" name="autori_select[]" multiple placeholder="<?= __('Cerca autori esistenti o aggiungine di nuovi...') ?>" data-initial-authors="<?php echo $initialAuthorsJson; ?>">
<!-- Options will be populated dynamically -->
</select>
<div id="autori_hidden"></div>
<p class="text-xs text-gray-500 mt-1"><?= __("Puoi selezionare più autori o aggiungerne di nuovi digitando il nome") ?></p>
</div>
<?php
// Contributor roles as entity pickers (issue #237). Same Choices.js +
// /api/search/autori autocomplete as authors, so an illustrator/
// translator/curator/colorist is a real author entity (findable by
// pseudonym, appears on the author page), not free text.
// Role-specific help text (issue #237): each field names its own role
// so the hint reads naturally instead of a generic "author" for all.
$contributorFields = [
'illustratori' => ['label' => __('Illustratore'), 'help' => __('Cerca un illustratore esistente o aggiungine uno nuovo digitando il nome')],
'traduttori' => ['label' => __('Traduttore'), 'help' => __('Cerca un traduttore esistente o aggiungine uno nuovo digitando il nome')],
'curatori' => ['label' => __('Curatore'), 'help' => __('Cerca un curatore esistente o aggiungine uno nuovo digitando il nome')],
'coloristi' => ['label' => __('Colorista'), 'help' => __('Cerca un colorista esistente o aggiungine uno nuovo digitando il nome (utile per i fumetti)')],
];
?>
<input type="hidden" id="contributors_entity_picker" name="contributors_entity_picker" value="0" />
<div class="form-grid-2">
<?php foreach ($contributorFields as $roleKey => $meta): ?>
<div>
<label for="<?= $roleKey ?>_select" class="form-label"><?= htmlspecialchars((string)$meta['label'], ENT_QUOTES, 'UTF-8') ?></label>
<select id="<?= $roleKey ?>_select" name="<?= $roleKey ?>_select[]" multiple
placeholder="<?= __('Cerca o aggiungi...') ?>"
data-initial-contributors="<?php echo $initialContributorsJson[$roleKey]; ?>"></select>
<div id="<?= $roleKey ?>_hidden"></div>
<p class="text-xs text-gray-500 mt-1"><?= htmlspecialchars((string)$meta['help'], ENT_QUOTES, 'UTF-8') ?></p>
</div>
<?php endforeach; ?>
</div>
<div class="mt-2 text-xs text-gray-500" id="genre_path_preview" style="min-height:1.25rem;">
<!-- Percorso selezionato -->
</div>
<!-- Publishers with Choices.js (multi-value, issue #143) -->
<div>
<label for="editori_select" class="form-label"><?= __("Editori") ?></label>
<select id="editori_select" name="editori_select[]" multiple placeholder="<?= __('Cerca editori esistenti o aggiungine di nuovi...') ?>" data-initial-publishers="<?php echo $initialPublishersJson; ?>">
<!-- Options populated dynamically -->
</select>
<div id="editori_hidden"></div>
<p class="text-xs text-gray-500 mt-1"><?= __("Puoi selezionare più editori o aggiungerne di nuovi digitando il nome") ?></p>
</div>
<!-- Book Status -->
<div>
<label for="stato" class="form-label"><?= __("Disponibilità") ?></label>
<?php $statoCorrente = strtolower((string) ($book['stato'] ?? '')); ?>
<select id="stato" name="stato" class="form-input">
<option value="disponibile" <?php echo $statoCorrente === 'disponibile' ? 'selected' : ''; ?>><?= __("Disponibile") ?></option>
<option value="non_disponibile" <?php echo $statoCorrente === 'non_disponibile' ? 'selected' : ''; ?>><?= __("Non Disponibile") ?></option>
<option value="prestato" <?php echo $statoCorrente === 'prestato' ? 'selected' : ''; ?>><?= __("Prestato") ?></option>
<option value="prenotato" <?php echo $statoCorrente === 'prenotato' ? 'selected' : ''; ?>><?= __("Prenotato") ?></option>
<option value="danneggiato" <?php echo $statoCorrente === 'danneggiato' ? 'selected' : ''; ?>><?= __("Danneggiato") ?></option>
<option value="perso" <?php echo $statoCorrente === 'perso' ? 'selected' : ''; ?>><?= __("Perso") ?></option>
</select>
<p class="text-xs text-gray-500 mt-1"><?= __("Status attuale di questa copia del libro") ?></p>
</div>
<!-- Description -->
<div>
<label for="descrizione" class="form-label"><?= __("Descrizione") ?></label>
<textarea id="descrizione" name="descrizione" rows="4" class="form-input" placeholder="<?= __('Descrizione del libro...') ?>"><?php echo HtmlHelper::e($book['descrizione'] ?? ''); ?></textarea>
</div>
</div>
</div>
<!-- Dewey Classification Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-tags text-primary"></i>
<?= __("Classificazione Dewey") ?>
</h2>
</div>
<div class="card-body form-section">
<input type="hidden" name="classificazione_dewey" id="classificazione_dewey" value="<?php echo HtmlHelper::e($book['classificazione_dewey'] ?? ''); ?>" />
<!-- Chip Dewey selezionato -->
<div id="dewey_chip_container" class="mb-4" style="display: none;">
<label class="form-label"><?= __("Classificazione selezionata:") ?></label>
<div id="dewey_chip" class="inline-flex items-center gap-2 bg-blue-100 text-blue-800 px-3 py-2 rounded-lg">
<span class="font-mono font-bold" id="dewey_chip_code"></span>
<span class="text-sm" id="dewey_chip_name"></span>
<button type="button" id="dewey_chip_remove" class="text-gray-800 hover:text-blue-900" aria-label="<?= __('Rimuovi classificazione Dewey') ?>">
<i class="fas fa-times"></i>
</button>
</div>
</div>
<!-- Input manuale Dewey -->
<div class="mb-4">
<label for="dewey_manual_input" class="form-label"><?= __("Codice Dewey") ?></label>
<div class="flex gap-2">
<input type="text" id="dewey_manual_input" class="form-input" placeholder="<?= __('es. 599.9, 004.6782, 641.5945, 599.1') ?>" />
<button type="button" id="dewey_add_btn" class="btn btn-primary">
<i class="fas fa-plus"></i> <?= __("Aggiungi") ?>
</button>
</div>
<p class="text-xs text-gray-500 mt-1"><?= __("Inserisci qualsiasi codice Dewey (anche se non presente nell'elenco)") ?></p>
</div>
<!-- Navigazione per categorie (opzionale) -->
<details class="mb-4">
<summary class="cursor-pointer text-sm font-semibold text-gray-700 hover:text-gray-800">
<?= __("Oppure naviga per categorie") ?>
</summary>
<div class="mt-3 p-3 bg-gray-50 rounded">
<div id="dewey_breadcrumb" class="text-xs text-gray-600 mb-2 flex items-center gap-1">
<i class="fas fa-home"></i>
<span><?= __("Nessuna selezione") ?></span>
</div>
<div id="dewey_levels_container" class="space-y-2">
<!-- I select verranno aggiunti dinamicamente -->
</div>
</div>
</details>
<p class="text-xs text-gray-500 mt-2"><?= __("La classificazione Dewey è utilizzata per organizzare i libri per argomento secondo standard internazionali") ?></p>
<h3 class="text-lg font-semibold text-gray-900 mt-6 mb-4"><?= __("Genere") ?></h3>
<div class="form-grid-3">
<div>
<label for="radice_select" class="form-label"><?= __("Radice") ?></label>
<select id="radice_select" name="radice_id" class="form-input" data-initial-radice="<?php echo (int)$initialData['radice_id']; ?>">
<option value="0"><?= __("Seleziona radice...") ?></option>
</select>
<p class="text-xs text-gray-500 mt-1"><?= __("Livello principale (es. Prosa, Poesia, Teatro)") ?></p>
</div>
<div>
<label for="genere_select" class="form-label"><?= __("Genere") ?></label>
<select id="genere_select" class="form-input" disabled data-initial-genere="<?php echo (int)$initialData['genere_id']; ?>">
<option value="0"><?= __("Seleziona prima una radice...") ?></option>
</select>
<input type="hidden" name="genere_id" id="genere_id_hidden" value="<?php echo (int)$initialData['genere_id']; ?>" />
<p class="text-xs text-gray-500 mt-1" id="genere_hint"><?= __("Genere letterario del libro") ?></p>
</div>
<div>
<label for="sottogenere_select" class="form-label"><?= __("Sottogenere") ?></label>
<select id="sottogenere_select" class="form-input" disabled data-initial-sottogenere="<?php echo (int)$initialData['sottogenere_id']; ?>">
<option value="0"><?= __("Seleziona prima un genere...") ?></option>
</select>
<input type="hidden" name="sottogenere_id" id="sottogenere_id_hidden" value="<?php echo (int)$initialData['sottogenere_id']; ?>" />
<p class="text-xs text-gray-500 mt-1" id="sottogenere_hint"><?= __("Sottogenere specifico (opzionale)") ?></p>
</div>
</div>
<!-- Keywords -->
<div class="mt-4">
<label for="parole_chiave" class="form-label"><?= __("Parole Chiave") ?></label>
<input id="parole_chiave" name="parole_chiave" type="text" class="form-input" placeholder="<?= __('es. romanzo, fantasy, avventura (separare con virgole)') ?>" value="<?php echo HtmlHelper::e($book['parole_chiave'] ?? ''); ?>" />
<p class="text-xs text-gray-500 mt-1"><?= __("Inserisci parole chiave separate da virgole per facilitare la ricerca") ?></p>
</div>
</div>
</div>
<!-- Acquisition Details Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-shopping-cart text-primary"></i>
<?= __("Dettagli Acquisizione") ?>
</h2>
</div>
<div class="card-body form-section">
<div class="form-grid-3">
<div>
<label for="data_acquisizione" class="form-label"><?= __("Data Acquisizione") ?></label>
<input id="data_acquisizione" type="date" name="data_acquisizione" class="form-input" value="<?php echo HtmlHelper::e($book['data_acquisizione'] ?? ''); ?>" />
</div>
<div>
<label for="tipo_acquisizione" class="form-label"><?= __("Tipo Acquisizione") ?></label>
<input id="tipo_acquisizione" name="tipo_acquisizione" type="text" class="form-input" placeholder="<?= __('es. Acquisto, Donazione, Prestito') ?>" value="<?php echo HtmlHelper::e($book['tipo_acquisizione'] ?? ''); ?>" />
</div>
<div>
<label for="prezzo" class="form-label"><?= __("Prezzo (€)") ?></label>
<input id="prezzo" name="prezzo" type="number" step="0.01" class="form-input" placeholder="<?= __('es. 19.90') ?>" value="<?php echo HtmlHelper::e($book['prezzo'] ?? ''); ?>" />
</div>
</div>
</div>
</div>
<!-- Physical Details Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-ruler text-primary"></i>
<?= __("Dettagli Fisici") ?>
</h2>
</div>
<div class="card-body form-section">
<div class="form-grid-3">
<div>
<label for="tipo_media" class="form-label"><?= __("Tipo Media") ?></label>
<select id="tipo_media" name="tipo_media" class="form-input">
<?php foreach (\App\Support\MediaLabels::allTypes() as $value => $meta): ?>
<option value="<?= htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8') ?>" <?= ($book['tipo_media'] ?? 'libro') === $value ? 'selected' : '' ?>>
<?= __($meta['label']) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div>
<label for="formato" class="form-label"><?= __("Formato") ?></label>
<input id="formato" name="formato" type="text" class="form-input" placeholder="<?= __('es. Copertina rigida, Brossura') ?>" value="<?php echo HtmlHelper::e($book['formato'] ?? ''); ?>" />
</div>
<div>
<label for="numero_pagine" class="form-label"><?= __("Numero Pagine") ?></label>
<input id="numero_pagine" name="numero_pagine" type="number" class="form-input" placeholder="<?= __('es. 320') ?>" value="<?php echo HtmlHelper::e($book['numero_pagine'] ?? ''); ?>" />
</div>
<div>
<label for="peso" class="form-label"><?= __("Peso (kg)") ?></label>
<input id="peso" name="peso" type="number" step="0.001" class="form-input" placeholder="<?= __('es. 0.450') ?>" value="<?php echo HtmlHelper::e($book['peso'] ?? ''); ?>" />
</div>
</div>
<div>
<label for="dimensioni" class="form-label"><?= __("Dimensioni") ?></label>
<input id="dimensioni" name="dimensioni" type="text" class="form-input" placeholder="<?= __('es. 21x14 cm') ?>" value="<?php echo HtmlHelper::e($book['dimensioni'] ?? ''); ?>" />
</div>
<div class="form-grid-3">
<div>
<label for="copie_totali" class="form-label"><?= __("Copie Totali") ?> <span class="text-xs text-gray-500">(<?= __("Le copie disponibili vengono calcolate automaticamente") ?>)</span></label>
<input id="copie_totali" name="copie_totali" type="number" class="form-input" value="<?php echo (int)($book['copie_totali'] ?? 1); ?>" min="<?php echo $mode === 'edit' ? (int)($book['copie_totali'] ?? 1) : 1; ?>" />
<?php if ($mode === 'edit'): ?>
<p class="text-xs text-gray-600 mt-1">
<i class="fas fa-info-circle text-blue-500 mr-1"></i>
Puoi ridurre le copie solo se non sono in prestito, perse o danneggiate.
</p>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Library Management Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-warehouse text-primary"></i>
<?= __("Gestione Biblioteca") ?>
</h2>
</div>
<div class="card-body form-section">
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label for="numero_inventario" class="form-label"><?= __("Numero Inventario") ?></label>
<input id="numero_inventario" name="numero_inventario" type="text" class="form-input" placeholder="<?= __('es. INV-2024-001') ?>" value="<?php echo HtmlHelper::e($book['numero_inventario'] ?? ''); ?>" />
</div>
</div>
<!-- UX-1 + UX-7 (review): regroup the 8 series fields under a
dedicated <fieldset> with inline help text; each input ties
to its description via aria-describedby so screen-reader users
aren't left guessing the difference between gruppo / serie
padre / serie principale. Sub-card heading is in Italian
source ("Serie e collana"). -->
<fieldset class="border border-gray-200 rounded-xl p-4 mt-4">
<legend class="px-2 text-sm font-semibold text-gray-700"><i class="fas fa-layer-group text-primary mr-1"></i><?= __("Serie e collana") ?></legend>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4">
<div>
<label for="gruppo_serie_select" class="form-label"><?= __("Gruppo serie") ?></label>
<?php $gruppoSerieVal = (string)($book['gruppo_serie'] ?? ''); ?>
<select id="gruppo_serie_select" data-series-autocomplete="gruppo_serie" data-placeholder="<?= htmlspecialchars(__('es. Fairy Tail'), ENT_QUOTES, 'UTF-8') ?>" class="form-input" aria-describedby="gruppo_serie_help">
<option value=""></option>
<?php if ($gruppoSerieVal !== ''): ?><option value="<?= htmlspecialchars($gruppoSerieVal, ENT_QUOTES, 'UTF-8') ?>" selected><?= htmlspecialchars($gruppoSerieVal, ENT_QUOTES, 'UTF-8') ?></option><?php endif; ?>
</select>
<input type="hidden" id="gruppo_serie" name="gruppo_serie" value="<?php echo htmlspecialchars($gruppoSerieVal, ENT_QUOTES, 'UTF-8'); ?>" />
<p id="gruppo_serie_help" class="text-xs text-gray-500 mt-1"><?= __('Etichetta "ombrello" per spin-off (es. tutto il franchise di Fairy Tail).') ?></p>
</div>
<div>
<label for="serie_padre_select" class="form-label"><?= __("Serie padre / universo") ?></label>
<?php $seriePadreVal = (string)($book['serie_padre'] ?? ''); ?>
<select id="serie_padre_select" data-series-autocomplete="serie_padre" data-placeholder="<?= htmlspecialchars(__('es. I mondi di Aldebaran'), ENT_QUOTES, 'UTF-8') ?>" class="form-input" aria-describedby="serie_padre_help">
<option value=""></option>
<?php if ($seriePadreVal !== ''): ?><option value="<?= htmlspecialchars($seriePadreVal, ENT_QUOTES, 'UTF-8') ?>" selected><?= htmlspecialchars($seriePadreVal, ENT_QUOTES, 'UTF-8') ?></option><?php endif; ?>
</select>
<input type="hidden" id="serie_padre" name="serie_padre" value="<?php echo htmlspecialchars($seriePadreVal, ENT_QUOTES, 'UTF-8'); ?>" />
<p id="serie_padre_help" class="text-xs text-gray-500 mt-1"><?= __("Serie superiore nella gerarchia (es. l'universo che contiene cicli e stagioni).") ?></p>
</div>
<div>
<label for="tipo_collana" class="form-label"><?= __("Tipo serie") ?></label>
<select id="tipo_collana" name="tipo_collana" class="form-input" aria-describedby="tipo_collana_help">
<?php foreach ($seriesTypeOptions as $typeValue => $typeLabel): ?>
<option value="<?= HtmlHelper::e($typeValue) ?>" <?= $selectedSeriesType === $typeValue ? 'selected' : '' ?>><?= HtmlHelper::e($typeLabel) ?></option>
<?php endforeach; ?>
</select>
<p id="tipo_collana_help" class="text-xs text-gray-500 mt-1"><?= __('Tassonomia: serie / universo / ciclo / stagione / spin-off / arco / collana editoriale.') ?></p>
</div>
<div>
<label for="collana_select" class="form-label"><?= __("Serie principale") ?></label>
<?php $collanaVal = (string)($book['collana'] ?? ''); ?>
<select id="collana_select" data-series-autocomplete="collana" data-placeholder="<?= htmlspecialchars(__('es. Fairy Tail: 100 Years Quest'), ENT_QUOTES, 'UTF-8') ?>" class="form-input" aria-describedby="collana_help">
<option value=""></option>
<?php if ($collanaVal !== ''): ?><option value="<?= htmlspecialchars($collanaVal, ENT_QUOTES, 'UTF-8') ?>" selected><?= htmlspecialchars($collanaVal, ENT_QUOTES, 'UTF-8') ?></option><?php endif; ?>
</select>
<input type="hidden" id="collana" name="collana" value="<?php echo htmlspecialchars($collanaVal, ENT_QUOTES, 'UTF-8'); ?>" />
<p id="collana_help" class="text-xs text-gray-500 mt-1"><?= __("Nome specifico della serie a cui appartiene il libro.") ?></p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mt-3">
<div>
<label for="numero_serie" class="form-label"><?= __("Numero Serie") ?></label>
<input id="numero_serie" name="numero_serie" type="text" class="form-input" placeholder="<?= htmlspecialchars(__('es. 15'), ENT_QUOTES, 'UTF-8') ?>" value="<?php echo HtmlHelper::e($book['numero_serie'] ?? ''); ?>" />
</div>
<div>
<label for="ciclo_serie_select" class="form-label"><?= __("Ciclo / stagione") ?></label>
<?php $cicloSerieVal = (string)($book['ciclo_serie'] ?? ''); ?>
<select id="ciclo_serie_select" data-series-autocomplete="ciclo_serie" data-placeholder="<?= htmlspecialchars(__('es. Ciclo 1 - Aldebaran'), ENT_QUOTES, 'UTF-8') ?>" class="form-input">
<option value=""></option>
<?php if ($cicloSerieVal !== ''): ?><option value="<?= htmlspecialchars($cicloSerieVal, ENT_QUOTES, 'UTF-8') ?>" selected><?= htmlspecialchars($cicloSerieVal, ENT_QUOTES, 'UTF-8') ?></option><?php endif; ?>
</select>
<input type="hidden" id="ciclo_serie" name="ciclo_serie" value="<?php echo htmlspecialchars($cicloSerieVal, ENT_QUOTES, 'UTF-8'); ?>" />
</div>
<div>
<label for="ordine_ciclo" class="form-label"><?= __("Ordine ciclo") ?></label>
<input id="ordine_ciclo" name="ordine_ciclo" type="number" min="0" class="form-input" placeholder="1" value="<?php echo HtmlHelper::e((string)($book['ordine_ciclo'] ?? '')); ?>" />
</div>
<div>
<label for="altre_collane" class="form-label"><?= __("Altre serie") ?></label>
<textarea id="altre_collane" name="altre_collane" rows="2" class="form-input" placeholder="<?= htmlspecialchars(__('Una serie per riga'), ENT_QUOTES, 'UTF-8') ?>" aria-describedby="altre_collane_help"><?php echo HtmlHelper::e($book['altre_collane'] ?? ''); ?></textarea>
<p id="altre_collane_help" class="text-xs text-gray-500 mt-1"><?= __("Una serie per riga (le virgole sono trattate come parte del nome).") ?></p>
</div>
</div>
</fieldset>
<!-- /UX-1 fieldset -->
<div class="hidden">
<!-- placeholder retained for old DOM selectors -->
</div>
<div class="form-grid-2">
<div>
<label for="file_url" class="form-label"><?= __("File URL") ?></label>
<input id="file_url" name="file_url" type="text" class="form-input" placeholder="<?= __('Link al file digitale (se disponibile)') ?>" value="<?php echo HtmlHelper::e($book['file_url'] ?? ''); ?>" />
</div>
<div>
<label for="audio_url" class="form-label"><?= __("Audio URL") ?></label>
<input id="audio_url" name="audio_url" type="text" class="form-input" placeholder="<?= __('Link all\'audiolibro (se disponibile)') ?>" value="<?php echo HtmlHelper::e($book['audio_url'] ?? ''); ?>" />
</div>
</div>
<?php
// Hook: Allow plugins to add digital content upload fields (e.g., Uppy uploaders)
do_action('book.form.digital_fields', $book);
?>
<!-- Notes -->
<div>
<label for="note_varie" class="form-label"><?= __("Note Varie") ?></label>
<textarea id="note_varie" name="note_varie" rows="3" class="form-input" placeholder="<?= __('Note aggiuntive o osservazioni particolari...') ?>"><?php echo HtmlHelper::e($book['note_varie'] ?? ''); ?></textarea>
</div>
</div>
</div>
<!-- Cover Upload Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-image text-primary"></i>
<?= __("Copertina del Libro") ?>
</h2>
</div>
<div class="card-body">
<!-- Uppy Upload Area -->
<div>
<div id="uppy-upload" class="mb-4"></div>
<div id="uppy-progress" class="mb-4"></div>
<!-- Fallback file input (hidden, used by Uppy) -->
<input type="file" name="copertina" accept="image/*" style="display: none;" id="fallback-file-input" />
<!-- Cover preview area -->
<div id="cover-preview-container" class="mt-4">
<?php if (!empty($currentCover)): ?>
<div class="inline-flex flex-col items-start space-y-2">
<div class="relative group">
<img src="<?php echo HtmlHelper::e(url($currentCover)); ?>" alt="Copertina attuale" class="max-h-48 object-contain border border-gray-200 rounded-lg shadow-sm" onerror="this.dataset.error='true'; this.style.display='none';" />
</div>
<div class="flex items-center gap-2">
<span class="text-xs text-gray-500"><?= __("Copertina attuale") ?></span>
<button type="button" onclick="removeCoverImage()" class="text-xs text-red-600 hover:text-red-800 hover:underline flex items-center gap-1">
<i class="fas fa-trash"></i>
<?= __('Rimuovi') ?>
</button>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<!-- Campi nascosti per conservare i dati estratti evitando duplicazioni -->
<!-- Physical Location Section -->
<div class="card">
<div class="card-header">
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-map-marker-alt text-primary"></i>
<?= __("Posizione Fisica nella Biblioteca") ?>
</h2>
</div>
<div class="card-body form-section">
<div class="form-grid-2">
<div>
<label for="scaffale_id" class="form-label"><?= __("Scaffale") ?></label>
<select id="scaffale_id" name="scaffale_id" class="form-input">
<option value="0"><?= __("Seleziona scaffale...") ?></option>
<?php foreach ($scaffali as $s): ?>
<option value="<?php echo (int)$s['id']; ?>" <?php echo ((int)$s['id'] === (int)($book['scaffale_id'] ?? 0)) ? 'selected' : ''; ?>><?php echo htmlspecialchars('['.($s['codice'] ?? '').'] '.($s['nome'] ?? ''), ENT_QUOTES, 'UTF-8'); ?></option>
<?php endforeach; ?>
</select>
</div>
<div>
<label class="form-label"><?= __("Mensola") ?></label>
<?php
$mensoleOptions = [];
$selectedMensola = $initialMensolaId;
$selectedScaffale = (int)($book['scaffale_id'] ?? 0);
if ($selectedMensola && $selectedScaffale) {
foreach ($mensole as $m) {
if ((int)($m['scaffale_id'] ?? 0) === $selectedScaffale) {
$mensoleOptions[] = $m;
}
}
}
?>
<select id="mensola_select" name="mensola_id" class="form-input" <?php echo $selectedMensola ? '' : 'disabled'; ?> data-initial-mensola="<?php echo $selectedMensola; ?>">
<?php if (!$mensoleOptions): ?>
<option value="0"><?= __("Seleziona prima uno scaffale...") ?></option>
<?php else: ?>
<option value="0"><?= __("Seleziona mensola...") ?></option>
<?php foreach ($mensoleOptions as $mensola): ?>
<option value="<?php echo (int)$mensola['id']; ?>" <?php echo ((int)$mensola['id'] === $selectedMensola) ? 'selected' : ''; ?>>
<?php echo HtmlHelper::e(__('Livello') . ' ' . ($mensola['numero_livello'] ?? '')); ?>
</option>
<?php endforeach; ?>
<?php endif; ?>
</select>
</div>
</div>
<div class="form-grid-2 mt-3">
<div>
<label for="posizione_progressiva_input" class="form-label"><?= __("Posizione progressiva") ?></label>
<div class="flex flex-col gap-2">
<input type="number" min="1" name="posizione_progressiva" id="posizione_progressiva_input" class="form-input" value="<?php echo $initialPosizioneProgressiva ?: ''; ?>" placeholder="<?= __('Auto') ?>" />
<button type="button" id="btnAutoPosition" class="btn-outline w-full sm:w-auto"><i class="fas fa-sync mr-2"></i><?= __("Genera automaticamente") ?></button>
<p class="text-xs text-gray-500"><?= __("Lascia vuoto o usa \"Genera\" per assegnare automaticamente la prossima posizione disponibile.") ?></p>
</div>
</div>
<div>
<label for="collocazione_preview" class="form-label"><?= __("Collocazione calcolata") ?></label>
<input type="text" id="collocazione_preview" name="collocazione_preview" class="form-input bg-slate-900/20 text-slate-100" value="<?php echo HtmlHelper::e($initialCollocazione); ?>" readonly />
<p class="text-xs text-gray-500 mt-1"><?= __("Aggiornata in base a scaffale, mensola e posizione.") ?></p>
</div>
</div>
<p class="text-xs text-gray-500 mt-2"><?= __("La posizione fisica è indipendente dalla classificazione Dewey e indica dove si trova il libro sugli scaffali.") ?></p>
<div class="mt-3">
<button type="button" id="btnSuggestCollocazione" class="btn-outline"><i class="fas fa-magic mr-2"></i><?= __("Suggerisci collocazione") ?></button>
<span id="suggest_info" class="ml-2 text-xs text-gray-500"></span>
</div>
</div>
</div>
<!-- LibraryThing Plugin Fields -->
<?php if (!empty($libraryThingInstalled)): ?>
<div class="card">
<button type="button"
class="w-full card-header flex items-center justify-between cursor-pointer hover:bg-gray-50 transition-colors text-left border-0 bg-transparent"
style="display: flex; width: 100%;"
onclick="toggleLibraryThingAccordion()"
aria-expanded="false"
aria-controls="librarything-accordion-content">
<div>
<h2 class="form-section-title flex items-center gap-2">
<i class="fas fa-cloud text-gray-800"></i>
<?= __("LibraryThing") ?>
</h2>
<p class="text-sm text-gray-600 mt-1"><?= __("Campi estesi per l'integrazione con LibraryThing") ?></p>
</div>
<i id="librarything-accordion-icon" class="fas fa-chevron-down text-gray-600 transition-transform duration-200"></i>
</button>
<div id="librarything-accordion-content"
class="card-body form-section overflow-hidden transition-all duration-300"
style="max-height: 0; opacity: 0; padding: 0;"
aria-hidden="true">
<!-- Review & Rating -->
<div class="mb-6">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Recensione e Valutazione") ?></h3>
<div class="form-grid-2">
<div>
<label for="book-rating" class="form-label"><?= __("Valutazione") ?></label>
<select id="book-rating" name="rating" data-star-rating>
<option value=""><?= __("Nessuna valutazione") ?></option>
<?php for ($i = 1; $i <= 5; $i++): ?>
<option value="<?= $i ?>" <?= isset($book['rating']) && (int)$book['rating'] === $i ? 'selected' : '' ?>>
<?= $i ?> <?= $i === 1 ? __('stella') : __('stelle') ?>
</option>
<?php endfor; ?>
</select>
</div>
</div>
<div class="mt-3">
<label for="review" class="form-label"><?= __("Recensione") ?></label>
<textarea id="review" name="review" rows="4" class="form-input" placeholder="<?= __('La tua recensione del libro...') ?>"><?= HtmlHelper::e($book['review'] ?? '') ?></textarea>
</div>
<div class="form-grid-2 mt-3">
<div>
<label for="comment" class="form-label"><?= __("Commento Pubblico") ?></label>
<textarea id="comment" name="comment" rows="3" class="form-input" placeholder="<?= __('Commento pubblico...') ?>"><?= HtmlHelper::e($book['comment'] ?? '') ?></textarea>
</div>
<div>
<label for="private_comment" class="form-label"><?= __("Commento Privato") ?></label>
<textarea id="private_comment" name="private_comment" rows="3" class="form-input" placeholder="<?= __('Note private...') ?>"><?= HtmlHelper::e($book['private_comment'] ?? '') ?></textarea>
</div>
</div>
</div>
<!-- Physical Description -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Descrizione Fisica") ?></h3>
<div>
<label for="physical_description" class="form-label"><?= __("Descrizione Fisica") ?></label>
<input type="text" id="physical_description" name="physical_description" class="form-input" value="<?= HtmlHelper::e($book['physical_description'] ?? '') ?>" placeholder="<?= __('es. Hardcover, 500 pages') ?>">
<p class="text-xs text-gray-500 mt-1"><?= __("Nota: Peso e dimensioni sono nei campi nativi dell'app (sezione Dati Fisici)") ?></p>
</div>
</div>
<!-- Library Classifications -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Classificazioni Bibliotecarie") ?></h3>
<div class="form-grid-2">
<div class="col-span-2">
<label for="dewey_wording" class="form-label"><?= __("Descrizione Dewey") ?></label>
<input type="text" id="dewey_wording" name="dewey_wording" class="form-input" value="<?= HtmlHelper::e($book['dewey_wording'] ?? '') ?>" placeholder="<?= __('es. History & geography > History of Asia > ...') ?>">
</div>
<div>
<label for="lccn" class="form-label"><?= __("LCCN") ?></label>
<input type="text" id="lccn" name="lccn" class="form-input" value="<?= HtmlHelper::e($book['lccn'] ?? '') ?>" placeholder="<?= __('Library of Congress Control Number') ?>">
</div>
<div>
<label for="lc_classification" class="form-label"><?= __("Classificazione LC") ?></label>
<input type="text" id="lc_classification" name="lc_classification" class="form-input" value="<?= HtmlHelper::e($book['lc_classification'] ?? '') ?>" placeholder="<?= __('es. PS3566.A686') ?>">
</div>
<div>
<label for="other_call_number" class="form-label"><?= __("Altro Numero di Chiamata") ?></label>
<input type="text" id="other_call_number" name="other_call_number" class="form-input" value="<?= HtmlHelper::e($book['other_call_number'] ?? '') ?>">
</div>
</div>
</div>
<!-- Date Tracking (Reading) -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Date di Lettura") ?></h3>
<div class="form-grid-2">
<div>
<label for="entry_date" class="form-label"><?= __("Data Inserimento LibraryThing") ?></label>
<input type="date" id="entry_date" name="entry_date" class="form-input" value="<?= HtmlHelper::e($book['entry_date'] ?? '') ?>">
</div>
<div>
<label for="date_started" class="form-label"><?= __("Data Inizio Lettura") ?></label>
<input type="date" id="date_started" name="date_started" class="form-input" value="<?= HtmlHelper::e($book['date_started'] ?? '') ?>">
</div>
<div>
<label for="date_read" class="form-label"><?= __("Data Fine Lettura") ?></label>
<input type="date" id="date_read" name="date_read" class="form-input" value="<?= HtmlHelper::e($book['date_read'] ?? '') ?>">
</div>
</div>
<p class="text-xs text-gray-500 mt-2"><?= __("Nota: Data acquisizione è nel campo nativo 'Data Acquisizione' sopra") ?></p>
</div>
<!-- Catalog IDs -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Identificatori Catalogo") ?></h3>
<div class="form-grid-2">
<div>
<label for="bcid" class="form-label"><?= __("BCID") ?></label>
<input type="text" id="bcid" name="bcid" class="form-input" value="<?= HtmlHelper::e($book['bcid'] ?? '') ?>">
</div>
<div>
<label for="barcode" class="form-label"><?= __("Codice a Barre") ?></label>
<input type="text" id="barcode" name="barcode" class="form-input" value="<?= HtmlHelper::e($book['barcode'] ?? '') ?>" placeholder="<?= __('Barcode fisico') ?>">
</div>
<div>
<label for="oclc" class="form-label"><?= __("OCLC") ?></label>
<input type="text" id="oclc" name="oclc" class="form-input" value="<?= HtmlHelper::e($book['oclc'] ?? '') ?>" placeholder="<?= __('OCLC number') ?>">
</div>
<div>
<label for="work_id" class="form-label"><?= __("LibraryThing Work ID") ?></label>
<input type="text" id="work_id" name="work_id" class="form-input" value="<?= HtmlHelper::e($book['work_id'] ?? '') ?>">
</div>
<!-- ISSN moved to main form section (next to EAN) -->
</div>
</div>
<!-- Language & Acquisition -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Lingua e Provenienza") ?></h3>
<div class="form-grid-2">
<div>
<label for="original_languages" class="form-label"><?= __("Lingue Originali") ?></label>
<input type="text" id="original_languages" name="original_languages" class="form-input" value="<?= HtmlHelper::e($book['original_languages'] ?? '') ?>" placeholder="<?= __('es. English, Italian') ?>">
</div>
<div>
<label for="source" class="form-label"><?= __("Fonte/Venditore") ?></label>
<input type="text" id="source" name="source" class="form-input" value="<?= HtmlHelper::e($book['source'] ?? '') ?>" placeholder="<?= __('es. Amazon, Libreria XYZ') ?>">
</div>
<div>
<label for="from_where" class="form-label"><?= __("Da Dove Acquisito") ?></label>
<input type="text" id="from_where" name="from_where" class="form-input" value="<?= HtmlHelper::e($book['from_where'] ?? '') ?>">
</div>
</div>
</div>
<!-- Lending Tracking -->
<div class="mb-6 pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Tracciamento Prestiti") ?></h3>
<div class="form-grid-2">
<div>
<label for="lending_patron" class="form-label"><?= __("Prestato A") ?></label>
<input type="text" id="lending_patron" name="lending_patron" class="form-input" value="<?= HtmlHelper::e($book['lending_patron'] ?? '') ?>" placeholder="<?= __('Nome del prestatore') ?>">
</div>
<div>
<label for="lending_status" class="form-label"><?= __("Stato Prestito") ?></label>
<select id="lending_status" name="lending_status" class="form-input">
<option value=""><?= __("Non in prestito") ?></option>
<option value="on loan" <?= isset($book['lending_status']) && $book['lending_status'] === 'on loan' ? 'selected' : '' ?>><?= __("In prestito") ?></option>
<option value="returned" <?= isset($book['lending_status']) && $book['lending_status'] === 'returned' ? 'selected' : '' ?>><?= __("Restituito") ?></option>
<option value="overdue" <?= isset($book['lending_status']) && $book['lending_status'] === 'overdue' ? 'selected' : '' ?>><?= __("Scaduto") ?></option>
</select>
</div>
<div>
<label for="lending_start" class="form-label"><?= __("Data Inizio Prestito") ?></label>
<input type="date" id="lending_start" name="lending_start" class="form-input" value="<?= HtmlHelper::e($book['lending_start'] ?? '') ?>">
</div>
<div>
<label for="lending_end" class="form-label"><?= __("Data Fine Prestito") ?></label>
<input type="date" id="lending_end" name="lending_end" class="form-input" value="<?= HtmlHelper::e($book['lending_end'] ?? '') ?>">
</div>
</div>
</div>
<!-- Financial and Condition Fields -->
<div class="pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3"><?= __("Valore e Condizione") ?></h3>
<div class="form-grid-2">
<div>
<label for="value" class="form-label"><?= __("Valore Corrente Stimato") ?></label>
<input type="number" step="0.01" id="value" name="value" class="form-input" value="<?= HtmlHelper::e($book['value'] ?? '') ?>" placeholder="<?= __('es. 25.00') ?>">
<p class="text-xs text-gray-500 mt-1"><?= __("Valore di mercato attuale (diverso dal prezzo di acquisto)") ?></p>
</div>
<div>
<label for="condition_lt" class="form-label"><?= __("Condizione Fisica") ?></label>
<select id="condition_lt" name="condition_lt" class="form-input">
<option value=""><?= __("Seleziona...") ?></option>
<option value="As New" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'As New' ? 'selected' : '' ?>><?= __("Come Nuovo") ?></option>
<option value="Fine" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'Fine' ? 'selected' : '' ?>><?= __("Ottimo") ?></option>
<option value="Very Good" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'Very Good' ? 'selected' : '' ?>><?= __("Molto Buono") ?></option>
<option value="Good" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'Good' ? 'selected' : '' ?>><?= __("Buono") ?></option>
<option value="Fair" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'Fair' ? 'selected' : '' ?>><?= __("Discreto") ?></option>
<option value="Poor" <?= isset($book['condition_lt']) && $book['condition_lt'] === 'Poor' ? 'selected' : '' ?>><?= __("Scarso") ?></option>
</select>
</div>
</div>
<p class="text-xs text-gray-500 mt-2"><?= __("Nota: Il prezzo di acquisto è nel campo 'Prezzo' della sezione 'Dati di Acquisizione'") ?></p>
</div>
<!-- Frontend Visibility Preferences -->
<div class="pt-6 border-t border-gray-200">
<h3 class="text-md font-semibold text-gray-700 mb-3">
<i class="fas fa-eye text-primary mr-2"></i>
<?= __("Visibilità nel Frontend") ?>
</h3>
<p class="text-sm text-gray-600 mb-4"><?= __("Seleziona quali campi LibraryThing mostrare nella pagina pubblica del libro") ?></p>
<?php
// Parse current visibility settings
$ltFieldsVisibility = [];
if (!empty($book['lt_fields_visibility'])) {
$ltFieldsVisibility = json_decode($book['lt_fields_visibility'], true) ?: [];
}
// Get all LibraryThing fields
$ltFields = \App\Support\LibraryThingInstaller::getLibraryThingFields();
// Group fields by category for better UX
$fieldGroups = [
__('Recensione') => ['review', 'rating', 'comment'],
__('Date') => ['entry_date', 'date_started', 'date_read'],
__('Classificazioni') => ['dewey_wording', 'lccn', 'lc_classification', 'other_call_number'],
__('Identificatori') => ['bcid', 'barcode', 'oclc', 'work_id'],
__('Provenienza') => ['original_languages', 'source', 'from_where'],
__('Prestito') => ['lending_patron', 'lending_status', 'lending_start', 'lending_end'],
__('Altro') => ['physical_description', 'value', 'condition_lt']
];
?>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
<?php foreach ($fieldGroups as $groupName => $fields): ?>
<div class="border border-gray-200 rounded-lg p-3 bg-gray-50">
<h4 class="text-sm font-semibold text-gray-700 mb-2"><?= HtmlHelper::e($groupName) ?></h4>
<?php foreach ($fields as $fieldName): ?>
<?php if (isset($ltFields[$fieldName])): ?>
<label class="flex items-center space-x-2 text-sm py-1 cursor-pointer hover:bg-gray-100 rounded px-1 transition-colors">
<input
type="checkbox"
name="lt_visibility[<?= $fieldName ?>]"
value="1"
class="w-4 h-4 rounded border-gray-300 text-gray-900 focus:ring-gray-500"
<?= isset($ltFieldsVisibility[$fieldName]) && $ltFieldsVisibility[$fieldName] ? 'checked' : '' ?>
>
<span class="text-gray-700"><?= HtmlHelper::e(__($ltFields[$fieldName])) ?></span>
</label>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<p class="text-xs text-gray-500 mt-3">
<i class="fas fa-info-circle mr-1"></i>
<?= __("I campi selezionati saranno visibili nella pagina pubblica del libro. I commenti privati sono sempre nascosti nel frontend.") ?>
</p>
</div>
</div>
</div>
<?php endif; ?>
<!-- Submit Section -->
<?php