| 1 | (=_CODE |
|---|
| 2 | |
|---|
| 3 | my $dbs = LJ::get_dbs(); |
|---|
| 4 | my $dbh = $dbs->{'dbh'}; |
|---|
| 5 | my $dbr = $dbs->{'reader'}; |
|---|
| 6 | |
|---|
| 7 | my $remote = LJ::get_remote($dbs); |
|---|
| 8 | my $user = $FORM{'user'}; |
|---|
| 9 | my $userid = LJ::get_userid($dbs, $user); |
|---|
| 10 | $body = ""; |
|---|
| 11 | |
|---|
| 12 | unless ($remote) |
|---|
| 13 | { |
|---|
| 14 | $title = "Add Friend"; |
|---|
| 15 | $body = "(=H1 Login First H1=)(=P To add a user to your friends list you must first go and <A HREF=\"/login.bml?ret=1\">log in</A>. If you don't already have an account you can <a href=\"/create.bml\">create one</a> to track your friend's journals. P=)"; |
|---|
| 16 | return; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | unless ($user && $userid) |
|---|
| 20 | { |
|---|
| 21 | $title = "Error"; |
|---|
| 22 | $body = "Invalid or missing username given. To add a friend, go to the <A HREF=\"/friends/edit.bml\">edit friends</A> page."; |
|---|
| 23 | return; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | if ($FORM{'mode'} eq "add") |
|---|
| 27 | { |
|---|
| 28 | unless (LJ::did_post()) { |
|---|
| 29 | $title = "Error"; |
|---|
| 30 | $body = "(=H1 Error H1=)(=P (=REQUIREPOST=) P=)"; |
|---|
| 31 | return; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | my $gmask = 1; |
|---|
| 35 | foreach my $bit (1..30) { |
|---|
| 36 | next unless $FORM{"bit_$bit"}; |
|---|
| 37 | $gmask |= (1 << $bit); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | my %res = (); |
|---|
| 41 | LJ::do_request($dbh, { |
|---|
| 42 | "user" => $remote->{'user'}, |
|---|
| 43 | "mode" => "editfriends", |
|---|
| 44 | "ver" => $LJ::PROTOCOL_VER, |
|---|
| 45 | "editfriend_add_1_user" => $user, |
|---|
| 46 | "editfriend_add_1_fg" => $FORM{'editfriend_add_1_fg'}, |
|---|
| 47 | "editfriend_add_1_bg" => $FORM{'editfriend_add_1_bg'}, |
|---|
| 48 | "editfriend_add_1_groupmask" => $gmask, |
|---|
| 49 | }, \%res, { "noauth" => 1, "userid" => $remote->{'userid'} } ); |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | if ($res{'success'} eq "OK") |
|---|
| 53 | { |
|---|
| 54 | $title = "Friend Added!"; |
|---|
| 55 | $body = "(=H1 Success H1=)(=P User <B>$user</B> was added to your friend list. You can view your friends page <A HREF=\"$LJ::SITEROOT/users/$remote->{'user'}/friends\">here</A>. P=)"; |
|---|
| 56 | } else { |
|---|
| 57 | $title = "Error"; |
|---|
| 58 | $body = "(=H1 Error H1=)(=P $res{'errmsg'} P=)"; |
|---|
| 59 | } |
|---|
| 60 | return; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | # check to see if user is already a friend. |
|---|
| 64 | $sth = $dbr->prepare("SELECT * FROM friends WHERE userid=$remote->{'userid'} AND friendid=$userid"); |
|---|
| 65 | $sth->execute; |
|---|
| 66 | my $fr = $sth->fetchrow_hashref; |
|---|
| 67 | |
|---|
| 68 | if ($fr) { |
|---|
| 69 | $title .= "Modify Friend"; |
|---|
| 70 | $body .= "(=H1 Modify Friend H1=)(=P You already have <b>$user</b> listed as a friend. However, you can modify the colors you've chosen to represent him/her. P=)"; |
|---|
| 71 | } else { |
|---|
| 72 | $title .= "Add Friend"; |
|---|
| 73 | $body .= "(=H1 Add $user as a friend? H1=)(=P To add <B>$user</B> to your friends list, click the button below. P=)"; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | $body .= "<form method=post>"; |
|---|
| 77 | $body .= "<input type=hidden name=mode value=add>"; |
|---|
| 78 | $body .= "<input type=hidden name=user value=\"$user\">"; |
|---|
| 79 | |
|---|
| 80 | if ($fr) { |
|---|
| 81 | $body .= "<center><input type=submit value=\"Save.\"></center>"; |
|---|
| 82 | } else { |
|---|
| 83 | $body .= "<center><input type=submit value=\"Add $user!\"></center>"; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | ## let them pick friend groups |
|---|
| 87 | $body .= "(=H1 Friend Groups H1=)(=P What friend groups do you want to put this user in? Friend groups are used for filtering your friends list view and also for group-based viewing security of items. P=)<blockquote>"; |
|---|
| 88 | my $err; |
|---|
| 89 | my $greq = LJ::Protocol::do_request($dbs, "getfriendgroups", { |
|---|
| 90 | 'username' => $remote->{'user'}, |
|---|
| 91 | 'ver' => $LJ::PROTOCOL_VER, |
|---|
| 92 | }, \$err, { 'noauth' => 1 }); |
|---|
| 93 | |
|---|
| 94 | if (@{$greq->{'friendgroups'}}) { |
|---|
| 95 | foreach my $g (@{$greq->{'friendgroups'}}) { |
|---|
| 96 | my $ck = ($fr && ($fr->{'groupmask'} & (1 << $g->{'id'}))) ? |
|---|
| 97 | "checked='1'" : ""; |
|---|
| 98 | |
|---|
| 99 | # by default, newly added friends are in default view unless unchecked |
|---|
| 100 | $ck = "checked='1'" if (! $fr && $g->{'name'} eq "Default View"); |
|---|
| 101 | |
|---|
| 102 | $body .= "<input type='checkbox' value='1' name='bit_$g->{'id'}' $ck> "; |
|---|
| 103 | $body .= LJ::ehtml($g->{'name'}) . "<br />\n"; |
|---|
| 104 | } |
|---|
| 105 | } else { |
|---|
| 106 | $body .= "<i>No friend groups setup.</i>"; |
|---|
| 107 | } |
|---|
| 108 | $body .= "</blockquote>"; |
|---|
| 109 | |
|---|
| 110 | ## let them pick the colors |
|---|
| 111 | $body .= "(=H1 Colors H1=)(=P You may also optionally select the colors that will represent $user in your friends list. P=)"; |
|---|
| 112 | |
|---|
| 113 | $ret .= "<P><CENTER><TABLE CELLPADDING=4><TR><TD><B>Foreground</B></TD><TD><B>Background</B></TD></TR>\n"; |
|---|
| 114 | |
|---|
| 115 | my @color = (); |
|---|
| 116 | LJ::load_codes($dbs, { "color" => \@color }); |
|---|
| 117 | |
|---|
| 118 | my $sel = $fr || { 'fgcolor' => '#000000', |
|---|
| 119 | 'bgcolor' => '#FFFFFF', }; |
|---|
| 120 | |
|---|
| 121 | $ret .= "<TR>"; |
|---|
| 122 | $ret .= "<TD><SELECT NAME=\"editfriend_add_1_fg\">"; |
|---|
| 123 | foreach (@color) { |
|---|
| 124 | my $selected = $_->{'code'} eq $sel->{'fgcolor'} ? " SELECTED" : ""; |
|---|
| 125 | $ret .= "<OPTION VALUE=\"$_->{'code'}\"$selected>$_->{'item'}\n"; |
|---|
| 126 | } |
|---|
| 127 | $ret .= "</SELECT></TD>\n"; |
|---|
| 128 | $ret .= "<TD><SELECT NAME=\"editfriend_add_1_bg\">"; |
|---|
| 129 | foreach (@color) { |
|---|
| 130 | my $selected = $_->{'code'} eq $sel->{'bgcolor'} ? " SELECTED" : ""; |
|---|
| 131 | $ret .= "<OPTION VALUE=\"$_->{'code'}\"$selected>$_->{'item'}\n"; |
|---|
| 132 | } |
|---|
| 133 | $ret .= "</SELECT></TD>\n"; |
|---|
| 134 | $ret .= "</TR>\n"; |
|---|
| 135 | $ret .= "</TABLE>\n"; |
|---|
| 136 | |
|---|
| 137 | ### color swatch |
|---|
| 138 | my $col = 0; |
|---|
| 139 | $ret .= "<P><TABLE border=0 cellspacing=0 cellpadding=0>"; |
|---|
| 140 | foreach (@color) { |
|---|
| 141 | if ($col==0) { $ret .= "<TR>\n"; } |
|---|
| 142 | $col++; |
|---|
| 143 | my $ecolor = LJ::ehtml($_->{'item'}); |
|---|
| 144 | $ret .= "<TD bgcolor=$_->{'code'}><IMG SRC=\"/img/dot.gif\" WIDTH=14 HEIGHT=14 TITLE=\"$ecolor\" ALT=\"$ecolor\"></TD>\n"; |
|---|
| 145 | if ($col==23) { $ret .= "</TR>\n"; $col==0; } |
|---|
| 146 | } |
|---|
| 147 | if ($col) { $ret .= "</TR>\n"; $col==0; } |
|---|
| 148 | $ret .= "</TABLE>\n"; |
|---|
| 149 | $ret .= "<FONT SIZE=-2 FACE=\"Arial,Helvetica\">(Hover your mouse over a color to see its name)</FONT>"; |
|---|
| 150 | |
|---|
| 151 | $ret .= "</CENTER>\n"; |
|---|
| 152 | $body .= $ret; |
|---|
| 153 | |
|---|
| 154 | $body .= "</form>"; |
|---|
| 155 | |
|---|
| 156 | return; |
|---|
| 157 | |
|---|
| 158 | _CODE=) |
|---|
| 159 | (=PAGE |
|---|
| 160 | TITLE=>(=_CODE return $title; _CODE=) |
|---|
| 161 | BODY=>(=_CODE return $body; _CODE=) |
|---|
| 162 | PAGE=)(=_C <LJDEP> |
|---|
| 163 | link: htdocs/login.bml, htdocs/create.bml, htdocs/friends/edit.bml, htdocs/users |
|---|
| 164 | img: htdocs/img/dot.gif |
|---|
| 165 | post: htdocs/friends/add.bml |
|---|
| 166 | </LJDEP> _C=) |
|---|