==== //ccare/main/LiveJournal/htdocs/update.bml#5 - /u0/jaffray/p4/LiveJournal/htdocs/update.bml ====
--- /tmp/tmp.17582.0	Tue Jun 12 02:28:44 2001
+++ /u0/jaffray/p4/LiveJournal/htdocs/update.bml	Tue Jun 12 02:18:32 2001
@@ -4,6 +4,7 @@
  require 'ljprotocol.pl'; 
 
  use LJ::SpellCheck;
+ use LJ::TagGenerator;
 
  my $SELF = "/update.bml";
  
@@ -11,13 +12,20 @@
  $body = "";
  $bodyopts = "";
 
- my $remote = undef;
-
- if ($LJ::SERVER_DOWN) {
-     $body = &server_down_html();
+ sub done {
+     $body .= shift;
      return "";
  }
+ sub done_list {
+     my $msg = shift;
+     my @items = map {LI("(=_EH $_ _EH=)")} @_;
+     return done(P("$msg: " . B(UL(@items))));
+ }
+     
+ not $LJ::SERVER_DOWN
+   or return done(server_down_html());
 
+ my $remote = undef;
  my $mode = $FORM{'mode'};
  my $spellcheck_html;
  if ($LJ::SPELLER && $FORM{'do_spellcheck'}) {
@@ -45,19 +53,14 @@
      &LJ::do_request($dbh, \%FORM, \%res);
      
      $body .= "(=H1 Logging in to server... H1=)\n";
-     if ($res{'success'} eq "OK")
-     {
-	 my $message = "";
-	 if ($res{'message'}) {
-	     $message = "Also, the server has a message for you: <UL><LI><B>(=_EH $res{'message'} _EH=)</B></UL>";
-	 }
-	 $body .= "(=P Login successful.  Hello, (=_EH $res{'name'} _EH=)! $message P=)";
-     }
-     else
-     {
-	 $body .= "(=P Error logging on: <UL><LI><B>(=_EH $res{'errmsg'} _EH=)</B></UL> P=)";
-	 return "";
+     $res{success} eq "OK"
+       or return done_list("Error logging on", $res{errmsg});
+
+     my $message = "";
+     if ($res{'message'}) {
+         $message = "Also, the server has a message for you: <UL><LI><B>(=_EH $res{'message'} _EH=)</B></UL>";
      }
+     $body .= "(=P Login successful.  Hello, (=_EH $res{'name'} _EH=)! $message P=)";
 
      ## see if an "other" mood they typed in has an equivalent moodid
      if ($FORM{'prop_current_mood'} ne "") 
@@ -73,10 +76,39 @@
 	 }
      }
 
+     # get all the multiple selections from the friend group dialog.
+     # grep away the empty string. choke if the form is inconsistent.
+     my @groupbits = grep {$_} split '\0', ($FORM{groupmask} or "");
+     if ($FORM{security} ne "custom" and @groupbits) {
+         return done_list("Error updating journal", 
+                          'You should only select friend groups if you choose the ' .
+                          'Security level "Friend Groups".  Please go back and decide ' .
+                          'what security level you really want.');
+     }
+     if ($FORM{security} eq "custom" and not @groupbits) {
+         return done_list("Error updating journal",
+                          'You chose Security level "Friend Groups", but you didn\'t select ' .
+                          'any friend groups.  Please go back and either choose a different ' .
+                          'Security setting or select one or more friend groups.');
+     }
+     if (grep /\D/, @groupbits) {
+         return done_list("Error updating journal",
+                          'Your browser is confused, or LiveJournal has a bug. ' .
+                          'One or more of the following is not a valid friendgroup number: ',
+                          @groupbits);
+     }
+
      my $sec = "public";
      my $amask = 0;
      if ($FORM{'security'} eq "private") { $sec = "private"; }
      if ($FORM{'security'} eq "friends") { $sec = "usemask"; $amask = 1; }
+     if ($FORM{'security'} eq "custom") {
+         $sec = "usemask";
+         $amask = 0;
+         foreach my $bit (split '\0', $FORM{groupmask}) {
+             $amask |= (1 << $bit);
+         }
+     }
      $FORM{'security'} = $sec;
      $FORM{'allowmask'} = $amask;
      
@@ -86,29 +118,23 @@
      &LJ::do_request($dbh, \%FORM, \%res);
      
      $body .= "(=H1 Updating journal... H1=)\n";
-     if ($res{'success'} eq "OK")
-     {
-	 my $uri = "/users/$FORM{'user'}/";
-	 if ($FORM{'usejournal'}) {
-	     my $quj = $dbh->quote($FORM{'usejournal'});
-	     my $sth = $dbh->prepare("SELECT journaltype FROM user WHERE user=$quj");
-	     $sth->execute;
-	     my ($type) = $sth->fetchrow_array;
-	     if ($type eq "C") {
-		 $uri = "/community/$FORM{'usejournal'}/";
-	     } else {
-		 $uri = "/users/$FORM{'usejournal'}/";
-	     }	 
-	 }
-	 $body .= "(=P Update successful.  You may view your updated journal <A HREF=\"$uri\">here</A>. P=)";
-     }
-     else
-     {
-	 $body .= "(=P Error updating journal: <UL><LI><B>(=_EH $res{'errmsg'} _EH=)</B></UL> P=)";
-	 return "";
+     $res{success} eq "OK"
+       or return done_list("Error updating journal", $res{errmsg});
+
+     my $uri = "/users/$FORM{'user'}/";
+     if ($FORM{'usejournal'}) {
+         my $quj = $dbh->quote($FORM{'usejournal'});
+         my $sth = $dbh->prepare("SELECT journaltype FROM user WHERE user=$quj");
+         $sth->execute;
+         my ($type) = $sth->fetchrow_array;
+         if ($type eq "C") {
+             $uri = "/community/$FORM{'usejournal'}/";
+         } else {
+             $uri = "/users/$FORM{'usejournal'}/";
+         }	 
      }
-     
-     return "";     
+     return done("(=P Update successful.  You may view your updated journal " .
+                 "<a href='$uri'>here</a>. P=)");
  }
 
  if ($mode eq "" || $mode eq "full") 
@@ -208,12 +234,34 @@
 				   "", "($remote->{'user'}) -- default", map { $_, $_ } @access);
 	 }
 
+         my @friendgroups;
+         if ($remote) {
+             my $rows = $dbh->selectall_arrayref("SELECT   groupnum, groupname        " .
+                                                 "FROM     friendgroup                " .
+                                                 "WHERE    userid = $remote->{userid} " .
+                                                 "ORDER BY sortorder")
+               or return $dbh->errstr;
+             @friendgroups = map {@$_} @$rows;
+         }
+             
 	 $body .= "<P><B>Security Level:</B> ";
-	 $body .= &html_select({ 'name' => 'security', 'selected' => $FORM{'security'}, },
-			       "public", "Public",
-			       "private", "Private",
-			       "friends", "Friends");
+	 $body .= &html_select({ name => "security", selected => $FORM{security}, },
+			       public  => "Public",
+                               private => "Private",
+			       friends => "All Friends",
+                               ($remote ? (custom => "Friend Groups") : ()),
+                              );
 	 $body .= " (=HELP $LJ::SITEROOT/support/faqbrowse.bml?faqid=24 HELP=)";
+         if (@friendgroups) {
+             $body .= " Groups: ";
+             $body .= &html_select({
+                                    name => 'groupmask', selected => "",
+                                    multiple => 1, size => 2,
+                                   },
+                                   "" => "",
+                                   @friendgroups,
+                                  );
+         }
 	 my $checked;
 	 $checked = $FORM{'prop_opt_preformatted'} ? "CHECKED" : "";
 	 $body .= "<P> <B>Don't auto-format:</B><INPUT TYPE=CHECKBOX NAME=\"prop_opt_preformatted\" VALUE=1 $checked> (=HELP $LJ::SITEROOT/support/faqbrowse.bml?faqid=26 HELP=) &nbsp; ";

