=title head<= <=head body<= '/community/manage.bml', 'text' => $ML{'/community/members.bml.manage2'}, }); my %errors; my $remote = LJ::get_remote(); unless ($remote) { $ret .= ""; return $ret; } unless ($remote->{'journaltype'} eq 'P') { $ret .= ""; return $ret; } my $mode = "modify"; $mode = "create" if $GET{'mode'} eq 'create'; if (LJ::did_post()) { my $sth; my $cuser = LJ::canonical_username($POST{'cuser'}); my $cu = LJ::load_user($cuser); unless ($cu) { $errors{'username'} = $ML{'.error.notfound'}; } if ($cu && $cu->{'userid'} == $remote->{'userid'}) { $errors{'username'} = $ML{'.error.samenames'}; } # if we're changing rather than creating, check that we can if ($mode eq 'modify' && !LJ::can_manage_other($remote, $cu)) { $errors{'username'} = BML::ml('.error.noaccess', {'comm'=>$cuser}); } # if we're creating, community password must match if ($mode eq 'create' && $cu && !LJ::auth_okay($cu, $POST{'cpassword'})) { $errors{'password'} = $ML{'.error.badpassword'}; } # disallow changing the journal type if the journal has entries if ($mode eq 'create' && !%errors && !LJ::check_priv($remote, "changejournaltype", "")) { my $count; my $userid=$cu->{'userid'}+0; my $dbcr = LJ::get_cluster_reader($cu); $count = $dbcr->selectrow_array("SELECT COUNT(*) FROM log2 WHERE journalid=$userid AND posterid=journalid"); $errors{'username'} = $ML{'.error.hasentries'} if $count; } # if it's already a community, don't let them turn it into a community if ($mode eq 'create' && !%errors && $cu->{journaltype} eq 'C') { $errors{'username'} = $ML{'.error.alreadycomm'}; } # if we found errors, we'll redisplay the form below. otherwise, # proceed. unless (%errors) { my $dbh = LJ::get_db_writer(); my $cid = $cu->{'userid'}; my $qmembership = $POST{membership}; $qmembership = 'closed' unless $qmembership =~ m/(?:open|moderated|closed)/; $qmembership = $dbh->quote($qmembership); my $qpostlevel = $dbh->quote($POST{'postlevel'} eq "members" ? "members" : "select"); LJ::update_user($cu, { journaltype => 'C' }); if ($mode eq 'create') { $dbh->do("REPLACE INTO community (userid, membership, postlevel) VALUES ($cid, $qmembership, $qpostlevel)"); LJ::set_rel($cu, $remote, 'A'); # delete existing friends my $friends = LJ::get_friends($cid, undef, undef, 'force') || {}; LJ::remove_friend($cid, [ keys %$friends ]); } else { $dbh->do("UPDATE community SET membership=$qmembership, postlevel=$qpostlevel WHERE userid=$cid"); } my $nonmembers = $POST{'nonmember_posting'} + 0; my $moderated = $POST{'moderated'} + 0; LJ::set_userprop($cu, 'nonmember_posting', $nonmembers); LJ::set_userprop($cu, 'moderated', $moderated); if ($moderated && ! LJ::load_rel_user($cu->{'userid'}, 'M')->[0]) { LJ::set_rel($cu->{'userid'}, $remote->{'userid'}, 'M'); } $ret .= ""; if ($mode eq 'create') { $ret .= ""; } else { $ret .= ""; } $ret .= "