forked from webmin/authentic-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
authentic.pl
1530 lines (1352 loc) · 49.7 KB
/
authentic.pl
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
#
# Authentic Theme (https://github.com/authentic-theme/authentic-theme)
# Copyright Ilia Rostovtsev <[email protected]>
# Licensed under MIT (https://github.com/authentic-theme/authentic-theme/blob/master/LICENSE)
#
use strict;
our ($get_user_level,
$xnav,
%theme_config,
%theme_text,
%config,
%gconfig,
%tconfig,
%text,
$basic_virtualmin_domain,
$basic_virtualmin_menu,
$cb,
$tb,
$title,
$cloudmin_no_create_links,
$cloudmin_no_edit_buttons,
$cloudmin_no_global_links,
$current_theme,
$done_theme_post_save_server,
$mailbox_no_addressbook_button,
$mailbox_no_folder_button,
$module_index_link,
$module_index_name,
$nocreate_virtualmin_menu,
$nosingledomain_virtualmin_mode,
$page_capture,
$remote_user,
$root_directory,
$session_id,
$ui_formcount,
$theme_ui_post_header_text,
$user_module_config_directory,
$theme_webprefix);
do($ENV{'THEME_ROOT'} . "/authentic-init.pl");
sub theme_header
{
return if (fetch_content());
my $tref = ref($_[0]) eq 'ARRAY';
my $ttitle = $tref ? $_[0]->[0] : $_[0];
embed_header(
(($ttitle ne $title ? ($title ? "$ttitle - $title" : $ttitle) : $ttitle),
$_[7], theme_debug_mode(),
(@_ > 1 ? '1' : '0'),
($tref ? 1 : 0)));
my $body_initial = !http_x_request() ? ' data-load-initial="1"' : undef;
print '<body ' . header_body_data(undef) . '' . $body_initial . ' ' . $tconfig{'inbody'} . '>' . "\n";
embed_overlay_prebody() if (!http_x_request());
# Embed branding
embed_product_branding()
if (!http_x_request() &&
(!get_env('http_referer') || get_env('http_referer') =~ /(session|pam)_login\.cgi/) &&
!getvar('theme-goto', 'main', 'unset'));
if (@_ > 1 && $_[1] ne 'stripped') {
# Print default container
print '<div class="container-fluid col-lg-10 col-lg-offset-1" data-dcontainer="1">' . "\n";
my %this_module_info = &get_module_info(&get_module_name());
print '<div class="panel panel-default">' . "\n";
print '<div class="panel-heading">' . "\n";
print $tconfig{'preheader'};
print '<div class="header">
<div class="row">';
print '<div data-header-left id="headln2l" class="invisible col-sm-4">';
if (!$_[5] && !$tconfig{'noindex'}) {
my @avail = &get_available_module_infos(1);
my $nolo = get_env('anonymous_user') ||
get_env('ssl_user') ||
get_env('local_user') ||
get_env('http_user_agent') =~ /webmin/i;
if ($gconfig{'gotoone'} &&
$main::session_id &&
@avail == 1 &&
!$nolo)
{
print
"<a href='$theme_webprefix/session_login.cgi?logout=1'>",
"$text{'main_logout'}</a><br>";
} elsif ($gconfig{'gotoone'} && @avail == 1 && !$nolo) {
print "<a href=$theme_webprefix/switch_user.cgi>", "$text{'main_switch'}</a><br>";
}
}
if (!$_[4] && !$tconfig{'nomoduleindex'}) {
my $idx = $this_module_info{'index_link'};
my $mi = $module_index_link || "/" . &get_module_name() . "/$idx";
my $mt = $module_index_name || $text{'header_module'};
print "<a href=\"$theme_webprefix$mi\">$mt</a><br>\n";
}
if (ref($_[2]) eq "ARRAY" &&
!get_env('anonymous_user') &&
!$tconfig{'nohelp'})
{
print &hlink($text{'header_help'}, $_[2]->[0], $_[2]->[1]), "<br>\n";
} elsif (defined($_[2]) &&
!get_env('anonymous_user') &&
!$tconfig{'nohelp'})
{
print &hlink($text{'header_help'}, $_[2]), "<br>\n";
}
if ($_[3]) {
my %access = &get_module_acl();
if (!$access{'noconfig'} && !$config{'noprefs'}) {
my $cprog =
$user_module_config_directory ? "uconfig.cgi" :
"config.cgi";
print "<a href=\"$theme_webprefix/$cprog?", &get_module_name() . "\">", $text{'header_config'}, "</a><br>\n";
}
}
print "</div>\n";
if ($_[1]) {
print "<div data-current-module-name=\"$this_module_info{'desc'}\" id=\"headln2c\" class=\"col-sm-4\">",
"<img alt=\"$ttitle\" src=\"$_[1]\"></td>\n";
} else {
my $ts =
defined($tconfig{'titlesize'}) ? $tconfig{'titlesize'} :
"+2";
print "<div data-current-module-name=\"$this_module_info{'desc'}\" id='headln2c' class=\"col-sm-4\">",
($ts ? "<span data-main_title>" : ""), $ttitle, ($ts ? "</span>" : "");
print "<br>$_[9]\n" if ($_[9]);
if ($theme_ui_post_header_text) {
print "<span data-sub_title><br>$theme_ui_post_header_text</span>";
} else {
print "<p class=\"margined-bottom-5\"></p>";
}
print "</div>\n";
}
print "<div data-header-right id=\"headln2r\" class=\"col-sm-4\">";
print $_[6];
print "</div></div></div>\n";
print $tconfig{'postheader'};
print '</div>' . "\n";
print '<div class="panel-body">' . "\n";
}
$miniserv::page_capture = 1;
$miniserv::theme_header_captured = 1;
}
sub theme_footer
{
return if (fetch_content());
((!$miniserv::theme_header_captured && !$miniserv::page_capture) && return);
my %this_module_info = &get_module_info(&get_module_name());
for (my $i = 0; $i + 1 < @_; $i += 2) {
my $url = $_[$i];
if ($url ne '/' || !$tconfig{'noindex'}) {
if ($url eq '/') {
$url = "/?cat=$this_module_info{'category'}";
} elsif ($url eq '' && &get_module_name()) {
$url = "/" . &get_module_name() . "/" . $this_module_info{'index_link'};
} elsif ($url =~ /^\?/ && &get_module_name()) {
$url = "/" . &get_module_name() . "/$url";
}
$url = "$theme_webprefix$url" if ($url =~ /^\//);
$url = $url . "/" if ($url =~ /[^\/]$/ && $url !~ /.cgi/ && $url !~ /javascript:history/);
print
" <a style='margin-bottom: 15px;' class='btn btn-primary btn-lg page_footer_submit' href=\"$url\"><i class='fa fa-fw fa-arrow-left'> </i> <span>",
&text('main_return', $_[$i + 1]), "</span></a>\n";
}
}
print "</div>\n";
embed_port_shell() if (!http_x_request());
embed_footer((theme_debug_mode()),
(
(get_module_name() ||
get_env('request_uri') =~ /\/config.cgi\?/ ||
get_env('request_uri') =~ /\/uconfig.cgi\?/ ||
get_env('request_uri') =~ /\/webmin_search.cgi\?/ ||
get_env('request_uri') =~ /\/tconfig.cgi/ ||
get_env('request_uri') =~ /\/settings-editor_read.cgi/ ||
get_env('request_uri') =~ /\/settings-editor_favorites_read.cgi/ ||
get_env('request_uri') =~ /\/settings-logos.cgi/ ||
get_env('request_uri') =~ /\/settings-backgrounds.cgi/
) ? '1' : '0'
),
$_[0]
) if (!http_x_request());
embed_pm_scripts();
if (get_env('script_name') eq '/session_login.cgi' ||
get_env('script_name') eq '/pam_login.cgi')
{
embed_js_scripts();
}
if ($theme_config{'settings_hide_top_loader'} ne 'true' &&
get_env('script_name') ne '/session_login.cgi' &&
get_env('script_name') ne '/pam_login.cgi' &&
!http_x_request())
{
if (!getvar('error-fatal')) {
print '<div class="top-aprogress"></div>', "\n";
}
}
# Post-body header overlay
embed_overlay_postbody() if (!http_x_request());
print '</body>', "\n";
print '</html>', "\n";
}
sub theme_ui_print_header
{
my ($text, @args) = @_;
if (length($text)) {
$theme_ui_post_header_text = $text;
}
&header(@args);
}
sub theme_popup_prehead
{
print '<style>#popup .ui_form_end_submit {display: none}</style>';
}
sub theme_file_chooser_button
{
my $chroot = defined($_[3]) ? $_[3] : "/";
my $add = int($_[4]);
my $link = "chooser.cgi?add=$add&type=$_[1]&chroot=$chroot&file=\"+encodeURIComponent(ifield.value)";
my $icon = 'fa-fw fa-files-o -cs';
return get_chooser_button_template($link, $icon);
}
sub theme_user_chooser_button
{
my $link = "user_chooser.cgi?multi=$_[1]&user=\"+encodeURIComponent(ifield.value)";
my $icon = 'fa-user-o';
return get_chooser_button_template($link, $icon);
}
sub theme_group_chooser_button
{
my $link = "group_chooser.cgi?multi=$_[1]&group=\"+encodeURIComponent(ifield.value)";
my $icon = 'fa-group-o';
return get_chooser_button_template($link, $icon);
}
sub theme_interfaces_chooser_button
{
my $link = "net/interface_chooser.cgi?multi=$_[1]&interface=\"+encodeURIComponent(ifield.value)";
my $icon = 'fa2 fa2-plus-network';
return get_chooser_button_template($link, $icon);
}
sub theme_date_chooser_button
{
return
"<button data-day=\"$_[0]\" data-month=\"$_[1]\" data-year=\"$_[2]\" type=button class=\"btn btn-default heighter-28 chooser_button date_chooser_button\"><i class=\"fa fa-fw fa-calendar\"></i></button>\n";
}
sub theme_popup_window_button
{
my ($url, $w, $h, $scroll, $fields) = @_;
my $scrollyn = $scroll ? "yes" : "no";
my $icon = "fa-files-o -cs";
if ($url =~ /third_chooser|standard_chooser/) {
$icon = "fa-world";
}
my $rv = "<button class='btn btn-default chooser_button' type=button onClick='";
foreach my $m (@$fields) {
$rv .= "$m->[0] = form.$m->[1]; ";
}
my $sep = $url =~ /\?/ ? "&" : "?";
$rv .= "chooser = window.open(\"$url\"";
foreach my $m (@$fields) {
if ($m->[2]) {
$rv .= "+\"$sep$m->[2]=\"+encodeURIComponent($m->[0].value)";
$sep = "&";
}
}
$rv .= ", \"chooser\", \"toolbar=no,menubar=no,scrollbars=$scrollyn,resizable=yes,width=$w,height=$h\"); ";
foreach my $m (@$fields) {
$rv .= "chooser.$m->[0] = $m->[0]; ";
$rv .= "window.$m->[0] = $m->[0]; ";
}
$rv .= "'><i class=\"fa $icon vertical-align-middle\" ></i></button>";
return $rv;
}
sub theme_ui_upload
{
my ($name, $size, $dis, $tags, $multiple) = @_;
$size = &ui_max_text_width($size);
return "<input class='ui_upload' type=file name=\"" .
"e_escape($name) . "\" " . "size=$size " . ($dis ? "disabled=true" : "") . ($multiple ? " multiple" : "") .
($tags ? " " . $tags : "") . ">";
}
sub theme_icons_table
{
my $lt = $theme_config{'settings_right_table_links_type'};
my $sm = $lt eq '1' ? ' small-icons' : undef;
my $nl = $lt eq '0' ? 1 : undef;
if ($nl) {
# Print plain text links
print "<div class=\"links-row-padded\">";
print
"<div class=\"row-flex row-flex-cols-sm-1 row-flex-cols-md-2 row-flex-cols-lg-3 row-flex-cols-xl-3 row-flex-cols-xxl-4 links-row\">";
for (my $i = 0; $i < @{ $_[0] }; $i++) {
my $after;
if ($_[8]->[$i]) {
$after = $_[8]->[$i];
$after =~
s/ui_link/margined-left-4 btn btn-default btn-transparent-link btn-xxs btn-xxs-compact btn-hover-hide f__lnk_t_btn-el/g;
$after =~ s/>\((.*?)\)</>$1</g;
}
my $before;
$before = $_[7]->[$i];
print "<div class=\"col-flex-sm-6" . ($before ? " link-row-col" : " link-row-col-narrow") . "\">";
print "$before <a class='row-link' href='$_[0]->[$i]' " . (ref($_[4]) ? $_[4]->[$i] : $_[4]) .
">" . ($before ? "" : "<i class='fa fa-fw fa-angle-right'> </i>") .
"<span>@{[html_strip($_[1]->[$i], ' ')]}</span></a> $after";
print "</div>";
}
print "</div>";
print "</div>";
} else {
# Print icons
my $ff;
my $in = scalar(@{ $_[0] });
print "<div class=\"row icons-row$sm\">\n";
for (my $i = 0; $i < @{ $_[0] }; $i++) {
&generate_icon($_[2]->[$i], $_[1]->[$i], $_[0]->[$i], ref($_[4]) ? $_[4]->[$i] : $_[4],
$_[5], $_[6], $_[7]->[$i], $_[8]->[$i]);
$ff .= '<div class="icons-container-filler"></div>', "\n" if (!$sm);
}
if ($in < 2) {
$ff .= "$ff" x 16;
} elsif ($in < 4) {
$ff .= "$ff" x 8;
} elsif ($in < 8) {
$ff .= "$ff" x 4;
} elsif ($in < 16) {
$ff .= "$ff" x 2;
}
print "$ff</div>\n";
}
}
sub theme_generate_icon
{
my ($icon, $title, $link, $href, $width, $height, $before, $after) = @_;
my $icon_outer = $icon;
my $wp = $theme_webprefix;
my $lt = $theme_config{'settings_right_table_links_type'};
$icon =~ s/^$wp//g if ($wp);
$icon =~ s/\/images//g;
$icon =~ s/images//g;
my $grayscaled_table_icons = ($theme_config{'settings_right_table_grayscaled_icons'} ne 'false' ? 0 : 1);
my $animate_table_icons = ($theme_config{'settings_right_table_animate_icons'} ne 'false' ? 0 :
1);
(my $___svg = $icon) =~ s/.gif/.svg/;
(!-r $root_directory . "/" . get_module_name() . "/" . $icon_outer) &&
($icon_outer = undef);
my $mod = get_module_name();
my $images_modules = 'images/modules';
my $root_images = $root_directory . "/$current_theme/$images_modules/";
my $__icon = (-r $root_images . $icon ? $wp . "/$images_modules" . $icon :
-r $root_images . $mod . $icon ? $wp . "/$images_modules/" . $mod . $icon :
-r $root_images . $mod . $___svg ? $wp . "/$images_modules/" . $mod . $___svg :
$icon_outer ? $icon_outer :
($wp . "/images/not_found.svg"));
if ($lt eq '1') {
print '<div class="col-xs-1 small-icons-container' .
(!$_[6] && !$_[7] ? ' forged-xx-skip' : ' gl-icon-container') .
'' . (!$grayscaled_table_icons && ' grayscaled') . '' . (!$animate_table_icons && ' animated') .
'" data-title="' . $title . '" data-toggle="tooltip" data-container="body">';
if ($_[6] || $_[7]) {
if ($_[6]) {
print "<span class='hidden-forged hidden-forged-6'>$_[6]</span>\n";
}
if ($_[7]) {
print
"<span style='position: absolute; top:-2px; right: 2px;' class='hidden-forged hidden-forged-7 hidden-forged-7-small'>$_[7]</span>\n";
}
}
print "<a href=\"$link\" class=\"icon_link\">" . '<img class="ui_icon' .
($icon_outer && ' ui_icon_protected') . '" src="' . $__icon . '" alt="">';
print "<span class=\"hidden\">$title</span></a>\n";
print '</div>';
} else {
print '<div class="col-xs-1 icons-container' . (!$_[6] && !$_[7] ? ' forged-xx-skip' : ' gl-icon-container') .
'' . (!$grayscaled_table_icons && ' grayscaled') . '' . (!$animate_table_icons && ' animated') . '" data-title="' .
(($lt eq '1') ? $title : '') . '" data-toggle="tooltip" data-container="body">';
if ($_[6] || $_[7]) {
if ($_[6]) {
print "<span class='hidden-forged hidden-forged-6' forged-xx-data forged-xx-sub>$_[6]</span>\n";
}
if ($_[7]) {
print
"<span style='position: absolute; top:3px; right: 4px;' class='hidden-forged hidden-forged-7'>$_[7]</span>\n";
}
}
print "<a href=\"$link\" class=\"icon_link\" data-title=\""
.
( ($_[6] || $_[7]) ? $title :
(string_contains($title, '<tt') ? "<span class='word-break-all'>$title</span>" : undef)
) .
"\" data-toggle=\"tooltip\" data-placement=\"auto bottom\" data-container=\"body\" " .
(string_contains($title, '<tt') ? " data-fbplacement" : undef) . ">" . '<img class="ui_icon' .
($icon_outer && ' ui_icon_protected') . '" src="' . $__icon . '" alt=""><br>';
print "$title</a>\n";
print "</div>\n";
}
}
sub theme_ui_columns_start
{
my ($heads, $width, $noborder, $tdtags, $title, $sortable) = @_;
my ($rv, $i);
$sortable = ' dtable-sortable' if ($sortable);
my $width_;
$width_ = ' w-auto-force" ' if ($width eq 'auto');
$rv .= "<table class=\"table table-striped table-hover table-condensed$sortable$width_\">" . "\n";
if ($title) {
$rv .= "<caption>$title</caption>\n";
}
if (ref($heads) && scalar(@{$heads})) {
$rv .= '<thead>' . "\n";
$rv .= '<tr>' . "\n";
for ($i = 0; $i < @$heads; $i++) {
$rv .= "<th " . (ref($tdtags) ? $tdtags->[$i] : undef) . ">";
$rv .= ($heads->[$i] eq '' ? '<br>' : $heads->[$i]);
$rv .= '</th>' . "\n";
}
$rv .= '</tr>' . "\n";
$rv .= '</thead>' . "\n";
}
$rv .= '<tbody>' . "\n";
return $rv;
}
sub theme_ui_columns_row
{
my ($cols, $tdtags) = @_;
my ($rv, $i);
$rv .= '<tr class="tr_tag">' . "\n";
if (ref($cols)) {
for ($i = 0; $i < @$cols; $i++) {
$rv .= "<td data-td-e " . (ref($tdtags) ? $tdtags->[$i] : undef) . ">\n";
$rv .= ($cols->[$i] !~ /\S/ ? '<br>' : $cols->[$i]);
$rv .= '</td>' . "\n";
}
}
$rv .= '</tr>' . "\n";
return $rv;
}
sub theme_ui_columns_header
{
my ($cols, $tdtags) = @_;
my ($rv, $i);
$rv .= '<thead>' . "\n";
$rv .= '<tr>' . "\n";
if (ref($cols)) {
for ($i = 0; $i < @$cols; $i++) {
$rv .= "<th " . (ref($tdtags) ? $tdtags->[$i] : undef) . ">";
$rv .= ($cols->[$i] eq '' ? '#' : $cols->[$i]);
$rv .= '</th>' . "\n";
}
}
$rv .= '</tr>' . "\n";
$rv .= '</thead>' . "\n";
return $rv;
}
sub theme_ui_columns_end
{
my $rv;
$rv .= '</tbody></table>' . "\n";
return $rv;
}
sub theme_ui_help
{
my ($title) = @_;
return (
"<sup class=\"ui_help\" data-container=\"body\" data-placement=\"auto right\" data-title=\"$title\" data-toggle=\"tooltip\"><i class=\"fa fa-0_80x fa-question-circle cursor-help\"></i></sup>"
);
}
sub theme_hlink
{
my $mod = $_[2] ? $_[2] : &get_module_name();
my $width = $_[3] || $tconfig{'help_width'} || $gconfig{'help_width'} || 600;
my $height = $_[4] || $tconfig{'help_height'} || $gconfig{'help_height'} || 400;
return
"<a onClick='window.open(\"$theme_webprefix/help.cgi/$mod/$_[1]\", \"help\", \"toolbar=no,menubar=no,scrollbars=yes,width=$width,height=$height,resizable=yes\"); return false' href=\"$theme_webprefix/help.cgi/$mod/$_[1]\">$_[0]</a>";
}
sub theme_ui_link
{
my ($href, $text, $class, $tags) = @_;
return (
"<a class='ui_link" . ($class ? " " . $class : "") . "' href='$href'" . ($tags ? " " . $tags : "") . ">$text</a>");
}
sub theme_ui_links_row
{
my ($links, $nopuncs) = @_;
my $link = "<a";
if (ref($links)) {
if (string_contains("@$links", $link)) {
@$links =
map {string_contains($_, $link) ? $_ : "<span class=\"btn btn-success ui_link ui_link_empty\">$_</span>"}
@$links;
return @$links ? "<div class=\"btn-group ui_links_row\" role=\"group\">" . join("", @$links) . "</div><br>\n" :
"";
} else {
if ($nopuncs == 1) {
return @$links ? join(", ", @$links) . "<br>\n" : "";
} elsif ($nopuncs == 2) {
return @$links ? join(" ", @$links) . "<br>\n" : "";
} else {
my $dot = ".";
if (scalar(@$links) == 1) {
$dot = "";
}
return @$links ? join(", ", @$links) . "$dot<br>\n" : "";
}
}
}
}
sub theme_select_all_link
{
my ($field, $form, $text) = @_;
$form = int($form);
$text ||= $text{'ui_selall'};
return
"<a class='select_all' href='#' onclick='theme_select_all_link($form, \"$field\"); return false'><span>$text</span></a>";
}
sub theme_select_invert_link
{
my ($field, $form, $text) = @_;
$form = int($form);
$text ||= $text{'ui_selinv'};
return
"<a class='select_invert' href='#' onclick='theme_select_invert_link($form, \"$field\"); return false'><span>$text</span></a>";
}
sub theme_select_rows_link
{
my ($field, $form, $text, $rows) = @_;
$form = int($form);
my $js = "var sel = { " . join(",", map {"\"" . "e_escape($_) . "\":1"} @$rows) . " }; ";
$js .=
"for(var i=0; i<document.forms[$form].${field}.length; i++) { var r = document.forms[$form].${field}[i]; r.checked = sel[r.value]; \$(r).trigger(\"change\"); } ";
$js .= "return false;";
return "<a href='#' onClick='$js'><span>$text</span></a>";
}
sub theme_ui_form_start
{
my ($script, $method, $target, $tags, $class) = @_;
my $rv;
$class = 'ui_form' if (!$class);
$rv .= "<form class=\"$class\" ";
$rv .= 'action="' . &html_escape($script) . '" ';
$rv .= ($method eq 'post' ? 'method="post" ' :
($method eq 'form-data' ? 'method="post" enctype="multipart/form-data" ' : 'method="get" '));
$rv .= ($target ? 'target="' . $target . '" ' : '');
$rv .= ($tags ? $tags : '');
$rv .= '>' . "\n";
return $rv;
}
sub theme_ui_form_end
{
$ui_formcount++;
my ($buttons, $width, $nojs) = @_;
my $rv;
if ($buttons && @$buttons) {
$rv .= "<table class='ui_form_end_buttons' " . ($width ? " width=$width" : "") . "><tr><td>\n";
my $b;
$rv .= '<div class="btn-group end_submits">';
foreach $b (@$buttons) {
if (ref($b)) {
$rv .= &ui_submit($b->[1], $b->[0], $b->[3], $b->[4], $b->[5], $b->[6]) . ($b->[2] ? " " . $b->[2] : "");
} elsif ($b) {
$rv .= "<span data-ui-form-end='inline'>$b</span>\n";
} else {
$rv .= "<span data-ui-form-end='empty'> </span>\n";
}
}
$rv .= '</div>';
$rv .= "</td></tr></table>\n";
}
$rv .= "</form>\n";
if (!$nojs) {
# When going back to a form, re-enable any text fields generated by
# ui_opt_textbox that aren't in the default state.
$rv .= "<script>\n";
$rv .= "var opts = document.getElementsByClassName('ui_opt_textbox');\n";
$rv .= "for(var i=0; i<opts.length; i++) {\n";
$rv .= " opts[i].disabled = document.getElementsByName(opts[i].name+'_def')[0].checked;\n";
$rv .= "}\n";
$rv .= "</script>\n";
}
return $rv;
}
sub theme_ui_textbox
{
my ($name, $value, $size, $dis, $max, $tags) = @_;
my $rv;
my $ids;
$ids = "_i_$main::ui_textbox_tcalled" if ($main::ui_textbox_tcalled++);
$rv .=
'<input style="display: inline; width: auto; height: 28px; padding-top: 0; padding-bottom: 2px; vertical-align: middle" class="form-control ui_textbox" type="text" ';
$rv .= 'id="' . "e_escape($name . $ids) . '" ';
$rv .= 'name="' . "e_escape($name) . '" ';
$rv .= 'value="' . "e_escape($value) . '" ';
$rv .= 'size="' . $size . '" ';
$rv .= ($dis ? 'disabled="true" ' : '');
$rv .= ($max ? 'maxlength="' . $max . '" ' : '');
$rv .= ($tags ? $tags : '');
$rv .= '>' . "\n";
return $rv;
}
sub theme_ui_password
{
my ($name, $value, $size, $dis, $max, $tags) = @_;
my $rv;
$rv .=
'<input spellcheck="false" style="display: inline; width: auto; height: 28px; padding-top: 0; padding-bottom: 2px; vertical-align:middle" class="form-control ui_password" type="password" ';
$rv .= 'name="' . "e_escape($name) . '" ';
$rv .= 'value="' . "e_escape($value) . '" ';
$rv .= 'size="' . $size . '" ';
$rv .= ($dis ? 'disabled="true" ' : '');
$rv .= ($max ? 'maxlength="' . $max . '" ' : '');
$rv .= ($tags ? $tags : '');
$rv .= '>' . "\n";
return $rv;
}
sub theme_ui_page_flipper
{
my ($msg, $inputs, $cgi, $left, $right, $farleft, $farright, $below) = @_;
my $rv = "<center class='ui_page_flipper'>";
my $class = 'fa fa-fw fa-lg text-semi-light vertical-align-baseline';
$rv .= &ui_form_start($cgi) if ($cgi);
# Far left link, if needed
if (@_ > 5) {
if ($farleft) {
$rv .=
"<a href='$farleft'>" . "<i " . get_button_tooltip('right_pagination_first', undef, 'auto top') .
"class='$class fa-angle-double-left'></i></a>\n";
} else {
$rv .= "<i class='$class fa-angle-double-left disabled'></i>\n";
}
}
# Left link
if ($left) {
$rv .=
"<a href='$left'>" . "<i " . get_button_tooltip('extensions_mail_pagination_left', undef, 'auto top') .
"class='$class fa-angle-left'></i></a>\n";
} else {
$rv .= "<i class='$class fa-angle-left disabled'></i>\n";
}
# Message and inputs
$rv .= $msg;
$rv .= " " . $inputs if ($inputs);
# Right link
if ($right) {
$rv .=
"<a href='$right'>" . "<i " . get_button_tooltip('extensions_mail_pagination_right', undef, 'auto top') .
"class='$class fa-angle-right'></i></a>\n";
} else {
$rv .= "<i class='$class fa-angle-right disabled'></i>\n";
}
# Far right link, if needed
if (@_ > 5) {
if ($farright) {
$rv .=
"<a href='$farright'>" . "<i " . get_button_tooltip('right_pagination_last', undef, 'auto top') .
"class='$class fa-angle-double-right'></i></a>\n";
} else {
$rv .= "<i class='$class fa-angle-double-right disabled'></i>\n";
}
}
$rv .= "<br>" . $below if ($below);
$rv .= &ui_form_end() if ($cgi);
$rv .= "</center>\n";
return $rv;
}
sub theme_ui_select
{
my ($name, $value, $opts, $size, $multiple, $missing, $dis, $tags) = @_;
my $rv;
$rv .=
"<select class='ui_select' " . "name=\"" . "e_escape($name) .
"\" " . ($size ? " size='$size'" : "") . ($multiple ? " multiple" : "") . ($dis ? " disabled=true" : "") .
($tags ? " " . $tags : "") . ">\n";
my ($o, %opt, $s, $v);
my %sel = ref($value) ? (map {$_, 1} @$value) : ($value, 1);
my $t = 'x-md-';
foreach $o (@$opts) {
$o = [$o] if (!ref($o));
$v = ($o->[1] || $o->[0]);
$rv .=
"<option value=\"" .
"e_escape($o->[0]) . "\"" . ($sel{ $o->[0] } ? " selected" : "") . ($o->[2] ne '' ? " " . $o->[2] : "") . ">" .
(string_contains($v, $t) ? html_escape($v) : $v) . "</option>\n";
$opt{ $o->[0] }++;
}
foreach $s (keys %sel) {
if (!$opt{$s} && $missing) {
$rv .= "<option value=\"" . "e_escape($s) . "\"" . " selected>" .
($s eq "" ? " " : (string_contains($s, $t) ? html_escape($s) : $s)) . "</option>\n";
}
}
$rv .= "</select>\n";
return $rv;
}
sub theme_ui_radio
{
my ($name, $val, $opts, $dis) = @_;
my ($rv, $o);
my $rand = int rand(1e4);
foreach $o (@$opts) {
my $id = "e_escape($name . "_" . $o->[0]);
my $label = $o->[1] || $o->[0];
my $after;
if ($label =~ /^([\000-\377]*?)((<a\s+href|<input|<select|<textarea|<span|<br|<p|<label)[\000-\377]*)$/i) {
$label = $1;
$after = $2;
}
$label = trim($label);
my $bl = string_ends_with($label, '<br>') ? ' ds-bl-fs' : undef;
$rv .= "<span class=\"awradio awobject$bl\"><input class=\"iawobject\" type=\"radio\" ";
$rv .= 'name="' . "e_escape($name) . '" ';
$rv .= 'value="' . "e_escape($o->[0]) . '" ';
$rv .= ($o->[0] eq $val ? 'checked ' : '');
$rv .= ($dis ? 'disabled="true" ' : '');
$rv .= 'id="' . $id . '_' . $rand . '" ';
$rv .= $o->[2] . ' ';
$rv .= '><label class="lawobject" ';
$rv .= 'for="' . $id . '_' . $rand . '">';
$rv .= '' . (length $label ? " $label " : ' ');
$rv .= '</label></span>' . $after . "\n";
}
return $rv;
}
sub theme_ui_yesno_radio
{
my ($name, $value, $yes, $no, $dis) = @_;
$yes = 1 if (!defined($yes));
$no = 0 if (!defined($no));
if ($value =~ /^[0-9,.E]+$/ || !$value) {
$value = int($value);
}
return ui_radio($name, $value, [[$yes, $text{'yes'}], [$no, $text{'no'}]], $dis);
}
sub theme_ui_oneradio
{
my ($name, $value, $label, $sel, $tags, $dis) = @_;
my $id = "e_escape("${name}_${value}");
my $after;
my $rand = int rand(1e4);
if ($label =~ /^([^<]*)(<[\000-\377]*)$/) {
$label = $1;
$after = $2;
}
$label = trim($label);
my $bl = string_ends_with($label, '<br>') ? ' ds-bl-fs' : undef;
my $ret =
"<span class=\"awradio awobject$bl\"><input class=\"iawobject\" type=\"radio\" name=\"" .
"e_escape($name) . "\" " . "value=\"" .
"e_escape($value) . "\" " . ($sel ? " checked" : "") . ($dis ? " disabled=true" : "") . " id=\"$id\_$rand\"" .
($tags ? " " . $tags : "") . ">";
$ret .=
'<label class="lawobject" for="' . $id . '_' . $rand . '">' .
(length $label ? " $label " : ' ') . '</label></span>';
$ret .= "$after\n";
return $ret;
}
sub theme_ui_checkbox
{
return theme_ui_checkbox_local(@_);
}
sub theme_ui_textarea
{
my ($name, $value, $rows, $cols, $wrap, $dis, $tags) = @_;
$cols = &ui_max_text_width($cols, 1);
my $ids;
$ids = "_t_$main::ui_textarea_tcalled" if ($main::ui_textarea_tcalled++);
return "<textarea style='display: inline; width:100%;' class='form-control ui_textarea' " .
"name=\"" . "e_escape($name) . "\" " . "id=\"" . "e_escape($name . $ids) .
"\" " . "rows='$rows' cols='$cols'" . ($wrap ? " wrap=$wrap" : "") . ($dis ? " disabled=true" : "") .
($tags ? " $tags" : "") . ">" . &html_escape($value) . "</textarea>";
}
sub theme_ui_submit
{
my ($label, $name, $dis, $tags, $icon_class, $btn_class_extra) = @_;
my ($keys, $class, $icon) = get_button_style($label);
if ($icon_class && !$icon) {
$icon = "<i class=\"$icon_class\"></i>";
}
my $ids;
$ids = "_s_$main::ui_submit_tcalled" if ($main::ui_submit_tcalled++);
my $nbsp;
if ($label) {
$nbsp = " ";
}
return "<button class=\"btn btn-$class ui_submit ui_form_end_submit $btn_class_extra\" type=\"button\"" .
($name ne '' ? " name=\"" . "e_escape($name) . "\"" : "") .
($name ne '' ? " id=\"" . "e_escape($name . $ids) . "\"" : "") .
($dis ? " disabled=true" : "") . ($tags ? " " . $tags : "") . ">" . $icon . "$nbsp<span data-entry=\"$keys\">" .
&html_escape($label) . "$nbsp</span></button>\n" . "<input class=\"hidden\" type=\"submit\""
.
( $name ne '' ? " name=\"" . "e_escape($name) . "\" value=\"" . "e_escape($label) . "\"" :
""
) .
" >\n";
}
sub theme_ui_reset
{
my ($label, $dis) = @_;
my $rv;
$rv .= '<button class="btn btn-default ui_reset" style="height: 28px; vertical-align:middle" type="reset" ';
$rv .= ($dis ? 'disabled="disabled">' : '>');
$rv .= &html_escape($label);
$rv .= '</button>' . "\n";
return $rv;
}
sub theme_ui_button
{
my ($label, $name, $dis, $tags, $icon, $type, $btn_class_extra) = @_;
my $rv;
my $label_safe = &html_escape($label);
my $nbsp;
if ($label) {
$nbsp = " ";
}
if ($icon) {
$label_safe = "<i class=\"$icon\"></i>$nbsp<span data-entry>$label_safe$nbsp</span>";
}
$type = "button" if (!$type);
$rv .= "<button type=\"$type\" class=\"btn btn-default ui_button $btn_class_extra\" ";
$rv .= ($name ne '' ? 'name="' . "e_escape($name) . '" ' : '');
$rv .= ($dis ? 'disabled="disabled"' : '');
$rv .= ($tags ? ' ' . $tags : '') . '>';
$rv .= $label_safe;
$rv .= '</button>' . "\n";
return $rv;
}
sub theme_ui_pre_footer
{
my $rv;
$rv .= '</div>' . "\n";
$rv .= '</div>' . "\n";
return $rv;
}
sub theme_ui_tabs_start
{
my ($tabs, $name, $sel, $border) = @_;
my $rv;
$rv .= '<ul class="nav nav-tabs">' . "\n";
foreach my $t (@$tabs) {
if ($t->[0] eq $sel) {
$rv .=
'<li class="active"><a data-toggle="tab" onclick="return tab_action(\'' .
$name . '\', \'' . $t->[0] . '\')" href="#att_' . $t->[0] . '">' . $t->[1] . '</a></li>' . "\n";
} else {
$rv .=
'<li><a data-toggle="tab" onclick="return tab_action(\'' .
$name . '\', \'' . $t->[0] . '\')" href="#att_' . $t->[0] . '">' . $t->[1] . '</a></li>' . "\n";
}
}
$rv .= '</ul>' . "\n";
$rv .= '<div class="tab-content">' . "\n";
$main::ui_tabs_selected = $sel;
$rv .= &ui_hidden($name, $sel) . "\n";
return $rv;
}
sub theme_ui_tabs_end
{
my ($border) = @_;
my $rv;
$rv .= '</div>' . "\n";
return $rv;
}
sub theme_ui_tabs_start_tab
{
my ($name, $tab) = @_;
my $rv;
my $defclass = $tab eq $main::ui_tabs_selected ? 'active' : '';
$rv .= '<div id="att_' . $tab . '" class="tab-pane ' . $defclass . '">' . "\n";
return $rv;
}
sub theme_ui_tabs_end_tab
{
my $rv;
$rv .= '</div>' . "\n";
return $rv;
}
sub theme_ui_hr
{
my $rv;
$rv .= '<hr>' . "\n";
return $rv;
}
sub theme_ui_alert_box
{
my ($msg, $class, $style, $new_line, $desc_to_title, $desc_icon) = @_;