forked from virtualmin/virtualmin-registrar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit_onecontact.cgi
executable file
·105 lines (95 loc) · 2.94 KB
/
edit_onecontact.cgi
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
#!/usr/local/bin/perl
# Show a form to edit a single contact associated with a registrar
use strict;
no strict 'refs';
use warnings;
our (%text, %in);
our $module_name;
require './virtualmin-registrar-lib.pl';
&ReadParse();
&error_setup($text{'onecontact_err'});
# Get the Virtualmin domain
&can_domain($in{'dom'}) || &error($text{'contact_ecannot'});
my $d = &virtual_server::get_domain_by("dom", $in{'dom'});
# Get the account
my @accounts = &list_registrar_accounts();
my ($account) = grep { $_->{'id'} eq $in{'id'} } @accounts;
$account || &error($text{'contacts_eaccount'});
&ui_print_header($account->{'desc'},
$in{'new'} ? $text{'onecontact_create'}
: $text{'onecontact_edit'}, "");
my $cfunc = "type_".$account->{'registrar'}."_get_contact_classes";
my @classes = &$cfunc($account);
my $cls;
my $con;
if (!$in{'new'}) {
# Get the contact
$cfunc = "type_".$account->{'registrar'}."_list_contacts";
my ($ok, $contacts) = &$cfunc($account);
$ok || &error(&text('contacts_elist', $contacts));
($con) = grep { $_->{'id'} eq $in{'cid'} } @$contacts;
($cls) = grep { $con->{$_->{'field'}} eq $_->{'id'} } @classes;
$in{'cls'} = $cls->{'id'} if ($cls);
}
else {
# Set type from class
($cls) = grep { $_->{'id'} eq $in{'cls'} } @classes;
if ($cls && $cls->{'field'}) {
$con = { $cls->{'field'} => $cls->{'id'} };
}
}
&ui_print_header(undef, $text{'onecontact_title'}, "");
print &ui_form_start("save_onecontact.cgi", "post");
print &ui_hidden("id", $in{'id'});
print &ui_hidden("cid", $in{'cid'});
print &ui_hidden("new", $in{'new'});
print &ui_hidden("cls", $in{'cls'});
print &ui_table_start(&text('onecontact_header', $cls->{'desc'}),
"width=100%", 2);
my @schema = &get_contact_schema($account, undef, undef, $in{'new'}, $in{'cls'});
foreach my $s (@schema) {
my $n = $s->{'name'};
my $field;
if ($s->{'readonly'}) {
# Just show value
$field = $con->{$s->{'name'}};
next if ($in{'new'} && !$field);
if ($s->{'choices'}) {
my ($c) = grep { $_->[0] eq $field } @{$s->{'choices'}};
$field = $c->[1] if ($c);
}
}
elsif ($s->{'choices'}) {
# Select from menu
my @choices = @{$s->{'choices'}};
if ($s->{'opt'}) {
unshift(@choices,
[ undef, $text{'contact_default'} ]);
}
$field = &ui_select($n, $con->{$s->{'name'}},
\@choices, 1, 0, !$in{'new'});
}
elsif ($s->{'opt'} == 1) {
# Optional value
$field = &ui_opt_textbox($n,
$con->{$s->{'name'}}, $s->{'size'},
$text{'contact_default'});
}
else {
# Required value
$field = &ui_textbox($n,
$con->{$s->{'name'}}, $s->{'size'});
}
print &ui_table_row($text{'contact_'.$s->{'name'}}, $field);
}
print &ui_table_end();
if ($in{'new'}) {
print &ui_form_end([ [ undef, $text{'create'} ] ]);
}
else {
my $dfunc = "type_".$account->{'registrar'}."_delete_one_contact";
print &ui_form_end([ [ undef, $text{'save'} ],
defined(&$dfunc) ?
[ 'delete', $text{'delete'} ] : undef ]);
}
&ui_print_footer(&virtual_server::domain_footer_link($d));