body<= " unless LJ::text_in(\%POST); LJ::set_active_crumb('editfriends'); # this file used to be edit_do.bml, but edit.bml died, so we moved this # functionality to edit.bml, but we don't want the translators to have to # retranslate all of the phrases, so we're still using /edit_do.bml scope BML::set_language_scope("/friends/edit_do.bml"); my $remote = LJ::get_remote(); return LJ::bad_input($ML{'error.noremote'}) unless $remote; my $authas = $GET{'authas'} || $remote->{'user'}; my $getextra = $authas ne $remote->{'user'} ? "?authas=$authas" : ''; my $u = LJ::get_authas_user($authas); return LJ::bad_input("You could not be authenticated as the specified user.") unless $u; return BML::redirect("$LJ::SITEROOT/community/members.bml?comm=$u->{'user'}") if $u->{'journaltype'} eq 'C'; return LJ::bad_input("Cannot modify friends of this journal type.") unless $u->{'journaltype'} =~ /^[PSI]$/; my $ret; # no post, show edit form unless (LJ::did_post()) { # user switcher $ret .= "
\n"; $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'type' => ['P', 'S'] }); $ret .= "
\n\n"; $ret .= "
\n"; ### who has you defined as a friend? my %res = (); LJ::do_request({ "user" => $u->{'user'}, "mode" => "friendof", "ver" => $LJ::PROTOCOL_VER, }, \%res, { "noauth" => 1, 'u' => $u }); ### who do you have defined as a friend? my %resf = (); LJ::do_request({ "user" => $u->{'user'}, "mode" => "getfriends", "ver" => $LJ::PROTOCOL_VER, }, \%resf, { "noauth" => 1, 'u' => $u }); # build hash for checking if user is friend my %isfriend = map { $resf{"friend_${_}_user"}, 1 } 1..$resf{'friend_count'}; ### table of friend-ofs if ($res{'friendof_count'}) { $ret .= "\n"; $ret .= "\n"; $ret .= ""; $ret .= ""; $ret .= ""; my $friendnum = 6; # 1-5 are new friends from the add form for my $i (1..$res{'friendof_count'}) { my $fo_user = $res{"friendof_${i}_user"}; $ret .= ""; $ret .= ""; } $ret .= "
$ML{'.user'}$ML{'.name'}$ML{'.opt.addtolist'}
" . LJ::ljuser($fo_user) . ""; my $dis = $isfriend{$fo_user} ? 1 : 0; $ret .= LJ::html_check({ 'type' => 'check', 'name' => "editfriend_add_${friendnum}_user", 'id' => "editfriend_add_${friendnum}_user", 'value' => $fo_user, 'disabled' => $dis }); $friendnum++; $ret .= "
"; } ### table of friends if ($resf{'friend_count'}) { $ret .= "\n"; $ret .= "

"; $ret .= ""; $ret .= ""; $ret .= "\n"; foreach my $i (1..$resf{'friend_count'}) { my $fruser = $resf{"friend_${i}_user"}; $isfriend{$fruser} = 1; my $bgcolor = $resf{"friend_${i}_bg"} || "#FFFFFF"; my $fgcolor = $resf{"friend_${i}_fg"} || "#000000"; my $status = $resf{"friend_${i}_status"}; my $userlink = LJ::ljuser($fruser); if ($status eq 'deleted' || $status eq 'purged' || $status eq 'suspended') { $userlink = "$userlink"; } $ret .= ""; $ret .= "\n"; } $ret .= "
$ML{'.friend'}$ML{'.name'}$ML{'.opt.delete'}
$userlink"; $ret .= ""; $ret .= ""; $ret .= LJ::html_check({ 'type' => 'check', 'name' => "editfriend_delete_${fruser}", 'id' => "editfriend_delete_${fruser}"}); $ret .= "

\n\n"; } else { $ret .= "\n\n"; } ### add friends $ret .= "\n"; $ret .= "

\@color }); foreach my $i (1..5) { $ret .= ""; $ret .= LJ::html_text({ 'name' => "editfriend_add_${i}_user", 'size' => '15', 'maxlength' => '15', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }); $ret .= ""; $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_fg", 'selected' => '#000000', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }, map { lc($_->{'code'}), $_->{'item'} } @color ); $ret .= ""; $ret .= LJ::html_select({ 'name' => "editfriend_add_${i}_bg", 'selected' => '#ffffff', 'onchange' => "updatePreview(); return true;", 'onfocus' => "setFriend($i);" }, map { lc($_->{'code'}), $_->{'item'} } @color ); $ret .= "\n"; } $ret .= ""; ### color swatch my $col = 0; $ret .= ""; foreach (@color) { if ($col==0) { $ret .= "\n"; } $col++; my $ecolor = LJ::ehtml($_->{'item'}); $ret .= ""; if ($col==23) { $ret .= "\n"; $col==0; } } if ($col) { $ret .= "\n"; $col==0; } $ret .= ""; $ret .= "
$ecolor
($ML{'.hover'})
"; $ret .= "

$ML{'.needmore'}

\n"; ### ending submit block $ret .= "\n"; $ret .= "\n"; $ret .= "
\n"; return $ret; } # if they did a post, then process their changes if (LJ::did_post()) { my %request = (); $request{'mode'} = "editfriends"; $request{'ver'} = $LJ::PROTOCOL_VER; $request{'user'} = $u->{'user'}; foreach (grep { /^editfriend_/ } keys %POST) { $request{$_} = $POST{$_}; } my %response = (); LJ::do_request(\%request, \%response, { 'noauth' => 1, 'u' => $u }); if ($response{'success'} eq "OK") { # tell the user all is well return " LJ::journal_base($u) . "/friends"})." p?>"; } else { return "
  • $response{'errmsg'} p?>\n"; } } return $ML{'error.unknownmode'}; } _code?> <=body head<= }; # end qq{ } } _code?> <=head page?> link: htdocs/create.bml, htdocs/lostinfo.bml post: htdocs/friends/edit.bml _c?>