%%comment-login-anonymous-html%%
2002-10-02 08:54:00

%%preprocess%%
if ($session->request->connection!="https") {
 $newlocation= "https://".$site->name.$session->refreshURL;
  berror("Login should be SSL. Trying to redirect to $newlocation.",1);
 header("Location: $newlocation");
 //exit;
 }

if ($_REQUEST[email]!="" ) {
  if ($GLOBALS['session']->loginprocess() ) {
	$parent= $this->getParent();
	$parent->getRuntimeVars();

	if ($this->sitememberid=="0" && $this->created!="" && $this->p_announced=="") {
	    $GLOBALS[session]->applyPolicy();
	    $session= $GLOBALS[session];
	    $sitemember= $GLOBALS[sitemember];
	    $properties= "announced=".date("F j, Y \a\\t g:ia");
	    berror("Updating comment:$this->id to have sitemember=$sitemember->id, removing author, and setting properties to show announced.",1);
	    $query= "UPDATE comment SET sitememberid='$sitemember->id', author='', properties='$properties' WHERE id='$this->id'";
	    $result= mysql_query($query);
	    if (!$result) {
		berror("Error updating comment with query=$query",1);
		}
	    else berror("Comment update SUCCESS with query=$query",1);
	    $this->author="";
	    $this->sitememberid= $sitemember->id;


	    //send email to subscription list here
	    berror("comment-save-member-html: parent ($parent->title) subscription list is: $parent->p_subscriptionList.",1);
	    if ($parent->p_subscriptionList!="") {
		// format for display
		$this->beryliumToHtml();
		$this->getRuntimeVars();
		$site->getRuntimeVars();
		
		// correct this->baseUrl 
		$parent->realUrl= "http://$site->name".$parent->uri;
		
		// determine recipientlist query
		$recipientarray= explode(" ",$parent->p_recipientList);
		$this->recipientQuery= "0 ";
		
		foreach ($recipientarray AS $key=>$value) {
		    $this->recipientQuery.= " OR obj.id='$value' ";
		    }
		
		// construct the mailing list from current sitemembership
		$query= "SELECT member.email FROM sitemember, member WHERE sitemember.siteid='$site->id' AND sitemember.status='posted' AND member.id=sitemember.memberid ";
		if ($result= mysql_query($query)) {
		    while ($thismember= mysql_fetch_array($result)) {
			if ($bcc=="") $bcc= "Bcc: ";
			else $bcc.= ", ";
			$bcc.= $thismember[email];
			}
		    berror("comment-save-member-html: bcc looks like $bcc.",1);
		    }
		else berror("comment-save-member-html: member lookup failed on query: $query.",1);
	    
		// email to:
		$to= "newcomment@berylium.org";
		$subject= "[$parent->title] $this->title";
		
		// construct the other email headers
		$newline= "\r\n";
		$this->headers = "From: $site->name <server@berylium.org>$newline";
		$this->headers .= $bcc.$newline;
		$this->headers .= "X-Mailer: berylium/php$newline";
		$this->headers .= "MIME-Version: 1.0$newline";
		$this->headers .= "Content-type: text/html; charset=iso-8859-1$newline";
		
		// construct the email
		$this->emailbody= "
		<html>
		<body>
		<a href='http://$site->name/berylium/'>$site->name</a> received a <b>new comment</b> at <a href='$parent->realUrl#comment:$this->id'>$parent->title</a>:<br>
		<br>
		<br>
		<font size='+1'>$this->title</font><br>
		By $this->authorTag on $this->created
		<blockquote>$this->body</blockquote>
		<br>
		<br>
		Authors reserve the right to edit their comments after posting.
		<hr>
		This is an automated message, sent to you because you subscribed to <a href='$parent->realUrl'>this discussion</a>.<br>
		If you have received this email in error or multiple times or something else nasty has happened to you because of it, we apologize. Please hit reply and let us know what's up. Thanks.
		</body>
		</html>
		";
		
		// send the bloddy thing, already
		berror("document-announce-member-email: email looks like this: <br>$this->emailbody",2);
		mail($to, $subject, $this->emailbody, $this->headers);
		}
	    else berror("comment-save-member-html: $parent->title ($parent->objtype:$parent->id) has no p_subscriptionList, skipping email.",1);
	    }

       $newlocation= "$parent->baseUrl?method=view$session->cgi#comment:$this->id";
       if ($GLOBALS['debug']) berror("Logging in. Trying to redirect to $newlocation.",0);
       header("Location: $newlocation");
       exit;
       }
  }


%%header%%

%%css%%

%%template%%
<form method='post' action='$this->idUrl?method=login$session->cgi' class='.form'>
$this->hiddenvars
<table width='400' border='0' cellspacing='0' cellpadding='5' align='center'>
<tr> 
<td colspan=2>
Your comment ($this->title) has been saved anonymously. It will be updated when you log in.<br>
<b>$session->alert</b>
</td>
</tr><tr>
<td align='right' valign='top'>email:</td>
<td valign='top'> <input type='text' name='email' size='42' maxlength='255' value="$sitemember->email">
</td> </tr>
<tr> <td align='right' valign='top'>password:</td>
<td valign='top'> <input type='password' name='password' size='42' maxlength='255' value="">
</td> </tr>
<tr> <td>&nbsp;</td>
<td> <input type='submit' name='Submit' value='login' class='buttonstyle'>
<input type='submit' name='Clue' value='send my hint' class='buttonstyle'>
</td>
</tr>
</table>
</form>


%%listrow%%

%%nullobject%%
Something is not right-- the comment ($this->id) didn't save.

%%footer%%

%%postprocess%%

%%end of context%%
