LJSUP-17669: Login.bml form refactoring
[livejournal.git] / htdocs / community / join.bml
blob8fdedd1775d8d79029519eb451a81519f05afab4
1 <?page
2 title=><?_ml .title _ml?>
3 body<=
4 <?_code
6 #line 6
7     use strict;
9     LJ::set_active_crumb('joincomm');
11     my $ret;
13     my $remote = LJ::get_remote();
14     return "<?needlogin?>"
15         unless $remote;
17     # bad statusvis?
18     return "<?h1 $ML{'.error.statusvis.title'} h1?><?p $ML{'.error.statusvis.body'} p?>"
19         unless $remote->{statusvis} eq 'V';
21     # make sure a community doesn't join a community
22     return "<?h1 $ML{'Error'} h1?><?p $ML{'.label.commlogged'} p?>"
23         unless $remote->is_personal || $remote->is_identity;
25     # get info about the community
27     my $cu = LJ::load_user($GET{comm});
29     # does this community even exist?
30     return "<?h1 $ML{'Error'} h1?><?p $ML{'.label.errorcomminfo'} p?>"
31         unless $cu;
33     return "<?h1 $ML{'Error'} h1?><?p $ML{'.label.notcomm'} p?>"
34         unless $cu->is_community;
36     return "<?h1 $ML{'Error'} h1?><?p $ML{'.label.locked'} p?>"
37         if $cu->{statusvis} eq "L";
39     # ensure this user isn't banned
40     return "<?h1 $ML{'Sorry'} h1?><?p $ML{'.label.banned'} p?>"
41         if LJ::is_banned($remote, $cu);
43     # and make sure they're not already a member
44     return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.already.member'} p?>"
45         if LJ::is_friend($cu, $remote);
46         
47     # check valid email
48     unless ($remote->is_validated()) {
49         return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.email.notvalid'} p?>";
50     }
52     # make sure underage users can't join adult communities
53     my $adult_content;
54     unless ($remote->can_join_adult_comm( comm => $cu, adultref => \$adult_content )) {
55         my $adult_err;
56         if ($adult_content eq "concepts") {
57             $adult_err = BML::ml('.error.ischild', {'comm' => $cu->ljuser_display});
58         } elsif ($adult_content eq "explicit") {
59             $adult_err = BML::ml('.error.isminor', {'comm' => $cu->ljuser_display});
60         }
62         unless ($remote->best_guess_age) {
63             $adult_err .= " " . BML::ml('.error.setage', {'aopts' => "href='$LJ::SITEROOT/manage/profile/'"});
64         }
66         return "<?h1 $ML{'Error'} h1?><?p $adult_err p?>";
67     }
69     my $ci = LJ::get_community_row($cu);
70     my $cuserid = $ci->{'userid'};
72     LJ::text_out(\$ci->{'name'});
73     my $ecname = LJ::ehtml($ci->{'name'});
75     # get the list of maintainers and their usernames
76     my $dbr = LJ::get_db_reader();
77     my $admins = $dbr->selectcol_arrayref("SELECT u.user FROM useridmap u, reluser r ".
78                                           "WHERE r.userid=$cuserid AND r.targetid=u.userid AND r.type='A'") || [];
79     my $list = "<ul>";
80     foreach (sort @$admins) { $list .= "<li><?ljuser $_ ljuser?></li>"};
81     $list .= "</ul>";
83     my $next_links = "<?p $ML{'.label.you_can'} p?><ul>";
84     $next_links .= "<li><a href=\'" . $cu->journal_base . "'>". BML::ml('.label.read_recent_entries', {'user' => $cu->user}) . "</a></li>";
85     $next_links .= "<li><a href=\'" . $cu->profile_url . "'>" . BML::ml('.label.read_comm_info', {'user' => $cu->user}) . "</a></li>";
86     $next_links .= "<li><a href='$LJ::SITEROOT/site/search.bml'>".BML::ml('.label.search_other') . "</a></li>";
87     $next_links .= LJ::run_hook("join_comm_extra")
88         if LJ::are_hooks("join_comm_extra");
89     $next_links .= "</ul>";
91     # can't join closed communities
92     if ($ci->{membership} eq 'closed') {
93         $ret .= "<?h1 $ML{'Sorry'} h1?><?p " . BML::ml('.error.closed', { admins => $list }) . " p?>";
94         $ret .= $next_links;
95         return $ret;
96     }
98     # now do the join
99     if (LJ::did_post()) {
100         return "<?h1 $ML{'Error'} h1?><?p $ML{'error.invalidform'} p?>"
101             unless LJ::check_form_auth();
103         my ($code, $message) = LJ::join_community($remote, $cu);
105         unless ($code) {
106             return "<?h1 $ML{'Error'} h1?><?p $message p?>";
107         } elsif ($message) {
108             $ret = "<?h1 $ML{'.reqsubmitted.title'} h1?><?p $message p?> ";
109             $ret .= $next_links;
110             return $ret;
111         }
113         # add community as a friend if selected
114         if ($POST{addfriend}) {
115             BML::redirect("$LJ::SITEROOT/friends/add.bml?user=$cu->{user}");
116         }
118         # success message -- only shows if user didn't add the community as a friend
119         my $profile_url = $cu->profile_url;
120         $ret .= "<?h1 $ML{'.success'} h1?><?p " . BML::ml('.label.membernow6',
121                                                           { 'commname' => LJ::ljuser($cu) }) . " p?>";
122     } else {
123         my $commuser = $cu->{user};
124         my $cancel_text = $ML{'.btn.cancel'};
126         my $cancel_btn = "<script type='text/javascript' language='Javascript'> \n <!-- \n
127           document.write(\"<input type='button' value='$cancel_text' onclick='history.go(-1); return false;'>\");
128                \n // -->\n </script>";
130         if ($ci->{membership} ne 'open') {
131             $ret .= "<?h1 $ML{'.request.title'} h1?><?p ";
132             $ret .= BML::ml('.request.body', { comm => LJ::ljuser($cu) }) . "<br /> p?>";
133             $ret .= "<form method='post' action='join.bml?comm=$commuser'>";
134             $ret .= LJ::form_auth();
135             $ret .= "<?standout <input type='submit' value=\"$ML{'.button.join2'}\" /> ";
136             $ret .= "$cancel_btn standout?></form>";
137             return $ret;
138         }
140         $ret .= "<?h1 " . BML::ml('.label.sure2', {'comm' => LJ::ljuser($cu)}) . " h1?>";
141         $ret .= "<?p " . BML::ml('.label.expls2', {'commname' => $ecname}) . " p?>";
142         $ret .= $ci->{postlevel} eq "members" ?
143              "<?p " . BML::ml('.label.allowposting2', {'sitename' => $LJ::SITENAMESHORT}) . " p?>" :
144              "<?p " . BML::ml('.label.auth2', {'admins' => $list}) . " p?>";
146         $ret .= "<form method='post' action='join.bml?comm=$commuser'>";
147         $ret .= LJ::form_auth();
148         $ret .= "<table cellpadding='0' cellspacing='1' border='0'><tr>";
149         $ret .= "<td><input type='checkbox' name='addfriend' checked='checked'></td><td>";
150         $ret .= LJ::is_friend($remote, $cu) ? BML::ml('.label.addtofriends2.modify', {'comm' => LJ::ljuser($cu)}) : BML::ml('.label.addtofriends3', {'comm' => LJ::ljuser($cu)});
151         $ret .= "</td></tr><tr>";
152         $ret .= "<td>&nbsp;</td><td><span style='font-size: smaller;'>$ML{'.label.addtofriends.note2'}</span></td>";
153         $ret .= "</tr></table>";
154         $ret .= "<?standout <input type='submit' value=\"$ML{'.button.join2'}\" /> ";
155         $ret .= "$cancel_btn standout?></form>";
156     }
158     return $ret;
160 _code?>
162 <=body
163 page?><?_c <LJDEP>
164 link: htdocs/login.bml, htdocs/userinfo.bml
165 post: htdocs/community/join.bml
166 </LJDEP> _c?>