2 title=><?_ml .title _ml?>
7 use vars qw(%GET %POST);
9 LJ::set_active_crumb('acctstatus');
11 my $remote = LJ::get_remote();
12 return "<?needlogin?>" unless $remote;
14 return LJ::Lang::ml('account.status.error.unavailable')
15 unless $remote->is_visible || $remote->is_deleted;
17 my $authas = $GET{'authas'} || $remote->{'user'};
19 my $u = LJ::get_authas_user($authas);
20 %type = ( type => 'S' ) if $u->is_community;
21 # Need to check supermaintainer rights for community
22 $u = LJ::get_authas_user($authas, \%type);
23 return LJ::bad_input($ML{'error.invalidauth'})
26 # visibility status name mappings
27 my %statusvis = ( "V" => "$ML{'.journalstatus.select.activated'}",
28 "D" => "$ML{'.journalstatus.select.deleted'}" );
29 if ($u->is_suspended) {
30 %statusvis = ("S" => "$ML{'.journalstatus.select.suspended'}");
33 # process form submission
34 if (LJ::did_post() && LJ::check_referer('/accountstatus.bml')) {
37 my $statusvis = $POST{'statusvis'};
39 return "<?h1 $ML{'.header.success'} h1?>\n<?p " . $_[0] . " p?>";
43 return "<?h1 $ML{'Error'} h1?>\n<?p " . $_[0] . " p?>";
46 return $dberr->($ML{'error.invalidform'})
47 unless LJ::check_form_auth();
50 return LJ::bad_input($ML{'.error.nochange.suspend'})
54 return LJ::bad_input($ML{'.error.nochange.expunged'})
58 return LJ::bad_input($ML{'.error.invalid'})
59 unless $statusvis eq 'D' || $statusvis eq 'V';
61 # save changes of purge_community_entries/purge_comments
63 my $purge_comments = ($POST{'purge_comments'}) ? 1 : 0;
64 my $purge_community_entries = ($POST{'purge_community_entries'}) ? 1 : 0;
65 $u->set_prop("purge_external_content", "$purge_comments:$purge_community_entries");
69 return $ok->(BML::ml('.message.nochange', {'statusvis' => $statusvis{$statusvis} }))
70 if $u->statusvis eq $statusvis;
74 my $ip = BML::get_remote_ip();
76 my @date = localtime(time);
77 my $date = sprintf("%02d:%02d %02d/%02d/%04d", @date[2,1], $date[3], $date[4]+1, $date[5]+1900);
79 if ($statusvis eq 'D') {
81 $res = $u->set_deleted;
83 LJ::statushistory_add( $u, $remote, 'journal_status',
84 'Set to deleted via accountstatus.bml' );
87 # sending ESN status was changed
88 LJ::Event::SecurityAttributeChanged->new($u, {
89 action => 'account_deleted',
90 ip => BML::get_remote_ip(),
94 } elsif ($statusvis eq 'V') {
95 LJ::run_hooks('account_undelete', $u);
97 ## Restore previous statusvis of journal. It may be different
98 ## from 'V', it may be read-only, or locked, or whatever.
99 my @previous_status = grep { $_ ne 'D' } $u->get_previous_statusvis;
100 my $new_status = $previous_status[0] || 'V';
109 my $statushistory_msg = 'Undeleted via accountstatus.bml, '
110 . 'setting statusvis to ' . $new_status;
112 LJ::statushistory_add( $u, $remote, 'journal_status',
113 $statushistory_msg );
115 return $dberr->("Can't set status '$new_status'") unless $method;
120 LJ::Event::SecurityAttributeChanged->new($u , {
121 action => 'account_activated',
122 ip => BML::get_remote_ip(),
129 return $dberr->($ML{'.error.db'})
133 $ret .= $ok->(BML::ml('.message.success', {'statusvis' => $statusvis{$statusvis} }));
135 if ($statusvis eq 'D') {
136 $ret .= "<?p $ML{'.message.deleted'} p?>";
137 # optional stuff that gets printed after deletion
138 $ret .= LJ::run_hook("accountstatus.bml_after_deletion", $u, \%POST);
148 # authas switcher form
149 $ret .= "<form method='get' action='accountstatus.bml'>\n";
150 ## type = 'S' : Only Supermaintainers can delete communities
151 $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'showall' => 1, type => 'S' }) . "\n";
152 $ret .= "</form>\n\n";
155 $getextra = "?authas=$authas" unless $authas eq $remote->username;
156 $ret .= "<form method='post' action='accountstatus.bml$getextra'>\n";
157 $ret .= LJ::form_auth();
159 $ret .= "<?h1 $ML{'.journalstatus.head'} h1?><?p $ML{'.journalstatus.about'} p?>\n";
161 $ret .= LJ::run_hook("accountstatus_delete_text", $u);
163 my ($purge_comments, $purge_community_entries) = split /:/, $u->prop("purge_external_content");
165 if (($u->is_person || $u->is_identity) && !$u->is_suspended) {
166 $ret .= '<h3>' . $ML{'.label.purge_external_content'} . '</h3>';
167 $ret .= "<ul style='list-style:none;margin:0;padding:0;'><li><label for='purge_comments'>";
168 $ret .= LJ::html_check({ 'name' => 'purge_comments', 'id' => 'purge_comments', 'selected' => $purge_comments });
169 $ret .= "$ML{'.label.purge_comments'}</label></li>";
172 if ($u->is_person && !$u->is_suspended) {
173 $ret .= "<li><label for='purge_community_entries'>";
174 $ret .= LJ::html_check({ 'name' => 'purge_community_entries', 'id' => 'purge_community_entries', 'selected' => $purge_community_entries });
175 $ret .= "$ML{'.label.purge_community_entries'}</label></li></ul>";
178 $ret .= "<p>$ML{'.journalstatus.select.head'}\n";
179 $ret .= LJ::html_select({ 'name' => 'statusvis', 'selected' => $u->statusvis },
180 map { $_, $statusvis{$_} }
181 reverse sort keys %statusvis) . "\n";
182 $ret .= LJ::html_submit(undef, $ML{'.btn.status'},
183 { 'disabled' => $u->is_suspended }) . "\n";
184 $ret .= "</p>\n</form>\n";