htdocs/community/settings.bml
author mark
Wed Apr 15 04:44:57 2009 +0000
branchproduction
changeset 707 66c67e811173
parent 536 9fbd871d8aeb
child 729 994dc3820d95
permissions -rw-r--r--
http://bugs.dwscoalition.org/show_bug.cgi?id=295

Remove a heckuva lot of LJ blue still sitting around.

Patch by ursamajor.
     1 <?page
     2 title<=
     3 <?_code
     4  if ($GET{'mode'} eq 'create') {
     5     return $ML{'.title.create'};
     6  }
     7  else {
     8     return $ML{'.title.modify'};
     9  }
    10 _code?>
    11 <=title
    12 head<=
    13 <style type='text/css'>
    14     fieldset { display: block; width: 320px; border: 1px solid #ccc; margin: 0 15px 15px 0; padding: 8px; }
    15     fieldset div { min-height: 170px; }
    16     * html fieldset div { height: 190px; }
    17     *:first-child+html fieldset div { min-height: 190px; }
    18     #left-column, #right-column { float: left; }
    19     legend { color: #c1272c; font-size: 1.2em; font-weight: bold; }
    20     p.input-wrapper { margin-left: 27px; text-indent: -27px; }
    21     label { color: #444; }
    22     label b { color: #000; }
    23     .standout { clear: left; max-width: 695px; }
    24     .standout table { margin: 0 auto; }
    25 </style>
    26 <=head
    27 body<=
    28 <?_code
    29 {
    30     use strict;
    31     use vars qw(%GET %POST);
    32 
    33     my $ret; 
    34     my %errors;
    35 
    36 
    37     my $remote = LJ::get_remote();
    38 
    39     unless ($remote) {
    40         $ret .= "<?needlogin?>";
    41         return $ret;
    42     }
    43 
    44     unless ($remote->{'journaltype'} eq 'P') {
    45         $ret .= "<?h1 $ML{'Error'} h1?><?p $ML{'.error.maintainertype'} p?>";
    46         return $ret;
    47     }
    48 
    49     my $mode = "modify";
    50     $mode = "create" if $GET{'mode'} eq 'create';
    51 
    52     $ret .= "<form action='$LJ::SITEROOT/community/settings.bml' method='get'>";
    53     $ret .= LJ::make_authas_select($remote, { authas => $GET{authas}, type => "C" });
    54     $ret .= "</form>";
    55 
    56     if (LJ::did_post())
    57     {
    58         return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
    59             unless LJ::check_form_auth();
    60 
    61         my $sth;
    62         my $cuser = LJ::canonical_username($POST{'cuser'});
    63         my $cu = LJ::load_user($cuser);
    64         
    65         unless ($cu) {
    66             $errors{'username'} = $ML{'.error.notfound'};
    67         }
    68 
    69         if ($cu && $cu->{'userid'} == $remote->{'userid'}) {
    70             $errors{'username'} = $ML{'.error.samenames'};
    71         }
    72 
    73         # if we're changing rather than creating, check that we can
    74         if ($mode eq 'modify' && !LJ::can_manage_other($remote, $cu)) {
    75             $errors{'username'} = BML::ml('.error.noaccess', {'comm'=>$cuser});
    76         }
    77 
    78         # if we're creating, community password must match
    79         if ($mode eq 'create' && $cu && !LJ::auth_okay($cu, $POST{'cpassword'})) {
    80             $errors{'password'} = $ML{'.error.badpassword'};
    81         }
    82 
    83         # disallow changing the journal type if the journal has entries
    84         if ($mode eq 'create' && !%errors && !LJ::check_priv($remote, "changejournaltype", "")) {
    85             my $count;
    86             my $userid=$cu->{'userid'}+0;
    87             
    88             my $dbcr = LJ::get_cluster_reader($cu);
    89             $count = $dbcr->selectrow_array("SELECT COUNT(*) FROM log2 WHERE journalid=$userid AND posterid=journalid");
    90             
    91             $errors{'username'} = $ML{'.error.hasentries'} if $count;
    92         }
    93 
    94         # if it's already a community, don't let them turn it into a community
    95         if ($mode eq 'create' && !%errors && $cu->{journaltype} eq 'C') {
    96             $errors{'username'} = $ML{'.error.alreadycomm'};
    97         }
    98         
    99         # if we found errors, we'll redisplay the form below.  otherwise,
   100         # proceed.
   101         unless (%errors) {
   102             my $dbh = LJ::get_db_writer();
   103             my $cid = $cu->id;
   104 
   105             my $qmembership = $POST{membership};
   106             $qmembership = "closed" unless $qmembership =~ /^(?:open|moderated|closed)$/;
   107             my $qpostlevel = $POST{postlevel};
   108             $qpostlevel = "select" unless $qpostlevel =~ /^(?:anybody|members|select)$/;
   109 
   110             # postlevel and nonmember_posting are a single setting in the UI, but separate options in the backend
   111             # split them out so we can save them properly
   112             my $nonmember_posting = 0;
   113             if ($qpostlevel eq "anybody") {
   114                 $qpostlevel = "members";
   115                 $nonmember_posting = 1;
   116             }
   117 
   118             LJ::update_user($cu, { journaltype => 'C', password => '' });
   119             if ($mode eq 'create') {
   120                 LJ::set_rel($cu, $remote, 'A');
   121 
   122                 # delete existing friends
   123                 my $friends = LJ::get_friends($cid, undef, undef, 'force') || {};
   124                 LJ::remove_friend($cid, [ keys %$friends ]);
   125 
   126                 # log this to statushistory
   127                 my $msg = "account '" . $cu->user . "' converted to community";
   128                 $msg .= " (maintainer is '" . $remote->user . "')";
   129                 LJ::statushistory_add($cu, $remote, "change_journal_type", $msg);
   130             }
   131 
   132             LJ::set_comm_settings($cu, $remote, { membership => $qmembership,
   133                                    postlevel => $qpostlevel });
   134 
   135             # lazy-cleanup: if a community has subscriptions (most likely
   136             # due to a personal->comm conversion), nuke those subs.
   137             # (since they can't manage them anyway!)
   138             $cu->delete_all_subscriptions;
   139 
   140             # ... and migrate their interests to the right table
   141             $cu->lazy_interests_cleanup;
   142             LJ::run_hook("change_journal_type", $cu);
   143 
   144             my $moderated = $POST{moderated} ? 1 : 0;
   145 
   146             LJ::set_userprop($cu, 'nonmember_posting', $nonmember_posting);
   147             LJ::set_userprop($cu, 'moderated', $moderated);
   148 
   149             if ( LJ::is_enabled( 'adult_content' ) ) {
   150                 my $adult_content = $POST{'adult_content'};
   151                 $adult_content eq "none"
   152                     unless $adult_content eq "explicit" || $adult_content eq "concepts";
   153                 $cu->set_prop('adult_content', $adult_content);
   154             }
   155 
   156             if ($moderated && ! LJ::load_rel_user($cu->{'userid'}, 'M')->[0]) {
   157                 LJ::set_rel($cu->{'userid'}, $remote->{'userid'}, 'M');
   158               }
   159 
   160             # since journaltype changed
   161             $cu->invalidate_directory_record;
   162 
   163             $ret .= LJ::maintainer_linkbar($cu, "settings");
   164             $ret .= "<?h1 $ML{'.success'} h1?>";
   165             if ($mode eq 'create') {
   166                 $ret .= "<?p $ML{'.label.commcreated'} p?>";
   167             } else {
   168                 $ret .= "<?p $ML{'.label.commchanged'} p?>";
   169             }
   170 
   171             $ret .= "<?p $ML{'.label.rellinks'} <ul><li><a href='" . $cu->journal_base . "'>$ML{'.label.commsite'}</a></li>";
   172             $ret .= "<li><a href='" . $cu->profile_url() . "'>$ML{'.label.comminfo'}</a></li><li>"
   173                 . BML::ml('.label.managepage', { 'aopts' => 'href="/community/manage.bml"' }) . "</li></ul> p?>";
   174 
   175             return $ret;
   176         }
   177     }
   178 
   179     # we're either creating a new community or modifying settings of an existing one
   180     # based on whether $mode is 'create' or 'modify'. Most of the page is the same in
   181     # either case, and additionally we must preload existing settings when modifying.
   182 
   183     my ($cname, $c);
   184 
   185     $cname = $POST{'cuser'}; # if we're falling through with errors when creating
   186     
   187     my %info = (
   188                 'membership'=>$POST{'membership'} || 'open',
   189                 'postlevel'=>$POST{'postlevel'} || 'members',
   190                 'nonmember_posting'=>$POST{'nonmember_posting'} || 0,
   191                 'moderated'=>$POST{'moderated'} || 0,
   192                 );
   193 
   194     if ($mode eq 'modify') {
   195         if ($GET{comm}) {
   196             # old GET arg
   197             return BML::redirect("$LJ::SITEROOT/community/settings.bml?authas=$GET{comm}");
   198         }
   199         $cname = LJ::canonical_username($GET{'authas'});
   200         $c = LJ::load_user($cname);
   201         unless ($c) {
   202             # if no community was specified, redirect to manage.bml
   203             return BML::redirect("$LJ::SITEROOT/community/manage.bml");
   204         }
   205 
   206         unless ($c->{'journaltype'} eq 'C') {
   207             $ret .= "<?h1 $ML{'Error'} h1?><?p $ML{'.error.notcomm'} p?>";
   208             return $ret;
   209         } 
   210         my $dbr = LJ::get_db_reader();
   211         ($info{'membership'},$info{'postlevel'}) = 
   212             $dbr->selectrow_array("SELECT membership, postlevel FROM community WHERE userid=$c->{'userid'}");
   213         LJ::load_user_props($c, "nonmember_posting", "moderated");
   214         $info{'nonmember_posting'} = $c->{'nonmember_posting'} ? 1 : 0;
   215         $info{'moderated'} = $c->{'moderated'} ? 1 : 0;
   216     }
   217 
   218     $ret .= "<form method='post' action='settings.bml?mode=$mode'>";
   219     $ret .= LJ::form_auth();
   220 
   221     if ($mode eq 'create') {
   222         LJ::set_active_crumb('createcommunity');
   223           $ret .= "<?h2 $ML{'.label.commheader'} h2?>" .
   224               ($mode eq 'modify' ? "<?p $ML{'.label.commchange'} p?>" : "<?p " . BML::ml('.label.commcreate2', {'aopts' => "href='$LJ::SITEROOT/create.bml'"}) . " p?>");
   225           $ret .= "<?standout <table width='350' cellpadding='7'><tr valign='top'><td><b>$ML{'.label.maintainer'}</b></td>";
   226           $ret .= "<td><?ljuser $remote->{'user'} ljuser?><br />" . BML::ml('.label.maintainer.login2', {'aopts' => "href='$LJ::SITEROOT/login.bml?ret=1'"}) . "</td></tr>";
   227           $ret .= "<tr valign='top'><td><b>$ML{'.label.community'}</b></td>";
   228           $ret .= "<td>$ML{'.label.username'}<br /><input name='cuser' maxlength='25' value='$cname' /><br />";
   229           $ret .= "<?inerr $errors{'username'} inerr?><br />";
   230           $ret .= "$ML{'.label.password'}<br /><input name='cpassword' type='password' /><br />";
   231           $ret .= "<?inerr $errors{'password'} inerr?></td></tr></table> standout?>";
   232       } else {
   233           LJ::set_active_crumb('commsettings');
   234             $ret .= LJ::html_hidden('cuser', $cname);
   235             $ret .= LJ::maintainer_linkbar($c, "settings");
   236         }
   237 
   238     $ret .= "<div id='left-column'>";
   239 
   240     # membership levels
   241     $ret .= "<fieldset id='membership'>";
   242     $ret .= "<legend>$ML{'.label.membership'}</legend><div><?p $ML{'.label.whocanjoin'} p?>";
   243     $ret .= "<p class='input-wrapper'>";
   244     $ret .= LJ::html_check({ type => 'radio', name => 'membership', id => 'memopen', 
   245                              value => 'open', selected => ($info{membership} eq 'open' ? 1 : 0)});
   246     $ret .= "<label for='memopen'> $ML{'.label.openmemb'}</label></p><p class='input-wrapper'>";
   247     $ret .= LJ::html_check({ type => 'radio', name => 'membership', id => 'memmoderated', 
   248                              value => 'moderated', selected => ($info{membership} eq 'moderated' ? 1 : 0)});
   249     $ret .= " <label for='memmoderated'>$ML{'.label.moderatedmemb'}</label></p><p class='input-wrapper'>";
   250     $ret .= LJ::html_check({ type => 'radio', name => 'membership', id => 'memclosed', 
   251                              value => 'closed', selected => ($info{membership} eq 'closed' ? 1 : 0)});
   252     $ret .= "<label for='memclosed'> $ML{'.label.closedmemb2'}</label></p>";
   253     $ret .= "</div></fieldset>";
   254 
   255     # adult content
   256     if ( LJ::is_enabled( 'adult_content' ) ) {
   257         my $adult_content = $c ? $c->adult_content : "none";
   258 
   259         $ret .= "<fieldset id='adult-content'>";
   260         $ret .= "<legend>$ML{'.label.adultcontentheader2'}</legend><div><?p $ML{'.label.adultcontenttext2'} " . LJ::help_icon('adult_content') . " p?>";
   261 
   262         $ret .= "<p class='input-wrapper'>";
   263         $ret .= LJ::html_check({
   264             type => 'radio', id => 'adultnone', name => 'adult_content',
   265             value => 'none', selected => $adult_content eq "none" ? 1 : 0,
   266         });
   267         $ret .= " <label for='adultnone'>$ML{'.label.adultcontentnone2'}</label></p>";
   268 
   269         $ret .= "<p class='input-wrapper'>";
   270         $ret .= LJ::html_check({
   271             type => 'radio', id => 'adultconcepts', name => 'adult_content',
   272             value => 'concepts', selected => $adult_content eq "concepts" ? 1 : 0,
   273         });
   274         $ret .= " <label for='adultconcepts'>" . BML::ml('.label.adultcontentconcepts2', { age => 14 }) . "</label></p>";
   275 
   276         $ret .= "<p class='input-wrapper'>";
   277         $ret .= LJ::html_check({
   278             type => 'radio', id => 'adultexplicit', name => 'adult_content',
   279             value => 'explicit', selected => $adult_content eq "explicit" ? 1 : 0,
   280         });
   281         $ret .= " <label for='adultexplicit'>" . BML::ml('.label.adultcontentexplicit2', { age => 18 }) . "</label></p>";
   282 
   283         $ret .= "</div></fieldset>";
   284     }
   285 
   286     $ret .= "</div><div id='right-column'>";
   287 
   288     my $posting_access = "members";
   289     if ($info{postlevel} eq "select") {
   290         $posting_access = "select";
   291     } elsif ($info{nonmember_posting}) {
   292         $posting_access = "anybody";
   293     }
   294 
   295     $ret .= "<fieldset id='member-restrictions'>";
   296     $ret .= "<legend>$ML{'.label.postingaccess'}</legend><div><?p $ML{'.label.whocanpost2'} p?>";
   297 
   298     $ret .= "<p class='input-wrapper'>";
   299     $ret .= LJ::html_check({
   300         type => 'radio', id => 'postanybody', name => 'postlevel',
   301         value => 'anybody', selected => $posting_access eq "anybody" ? 1 : 0,
   302     });
   303     $ret .= " <label for='postanybody'>$ML{'.label.postingaccessanybody'}</label></p>";
   304 
   305     $ret .= "<p class='input-wrapper'>";
   306     $ret .= LJ::html_check({
   307         type => 'radio', id => 'postmembers', name => 'postlevel',
   308         value => 'members', selected => $posting_access eq "members" ? 1 : 0,
   309     });
   310     $ret .= " <label for='postmembers'>$ML{'.label.postingaccessmembers'}</label></p>";
   311 
   312     $ret .= "<p class='input-wrapper'>";
   313     $ret .= LJ::html_check({
   314         type => 'radio', id => 'postselect', name => 'postlevel',
   315         value => 'select', selected => $posting_access eq "select" ? 1 : 0,
   316     });
   317     $ret .= " <label for='postselect'>$ML{'.label.postingaccessselect'}</label></p>";
   318 
   319     $ret .= "<?p $ML{'.label.moderation'} p?>";
   320     $ret .= "<p class='input-wrapper'>";
   321     $ret .= LJ::html_check({ id => 'moderate', name => 'moderated', selected => $info{moderated} ? 1 : 0 });
   322     $ret .= " <label for='moderate'>$ML{'.label.moderationyes'}</label></p>";
   323 
   324     $ret .= "</div></fieldset>";
   325 
   326     $ret .= "</div>";
   327 
   328     $ret .= "<div style='clear: left; max-width: 695px;'><?standout <input type='submit' value='" .
   329         ($mode eq 'create' ? "$ML{'.button.createcommunity'}" : "$ML{'.button.changecommunity2'}") .
   330         "' /> standout?></div></form>";
   331 
   332     return $ret;
   333 }
   334 _code?>
   335 
   336 <=body
   337 page?>