%%comment-save-anonymous-html%%
$Date: 2003/03/07 20:40:53 $

%%preprocess%%
if ($this->status=="") {
	$this->status="posted";
	$this->public=1;
	$this->rank=100;
	}
	
if ($sitemember->role=="anonymous") {
	$this->rank=50;
	$this->p_sessionid= $session->id;
	if (trim($this->author=="")) $this->author= "Anonymous (#$session->id)";
	else $this->author= $this->author." (#$session->id)";
	$this->applyPolicy();
	}


%%header%%


%%css%%


%%template%%
<table width='90%' border='0' cellspacing='20' cellpadding='5' align='center'>
<tr> <td> <p><b>UPDATED! $this->objtype object id#$this->id ($this->name):</b></p>
<p>$this->propertiesList</p>
<p><a href='$session->refreshURL'>refresh</a> | <a href='$this->baseURL?method=edit$session->cgi'>edit</a> | <a href='$this->baseURL?method=create$session->cgi'>create new</a> | <a href='$this->baseURL?method=addchild$session->cgi'>add child</a> | <a href='#top'>top</a></p>
</td>
</tr>
</table>


%%listrow%%
 

%%nullobject%%
 

%%footer%%


%%postprocess%%
$query= "SELECT obj.* FROM comment AS obj WHERE obj.id='$this->id' ";
$this->selectObject($query);


berror("comment-save-member-html: comment parent is $this->parentobjtype:$this->parentid.",1);
$parent= $this->getParent();
$parent->getRuntimeVars();


// if new, send comment via email to all members of $parent->p_subscriptionList
if ($this->p_announced=="" && $_POST['authType']!="login") {
    berror("comment-save-member-html: parent ($parent->title) subscription list is: $parent->p_subscriptionList.",1);
    
    // set the announced property so that the announcement can only be sent once
    $this->p_announced= date("F j, Y \a\\t g:ia");
    $this->update= 1;
    $this->updateObject('$Id: comment-save-anonymous-html,v 1.7 2003/03/07 20:40:53 csnyder Exp $');
    berror("comment-save-member-html: set p_announced= $this->p_announced",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_subscriptionList);
	berror("comment-save-member-html: First recipient is $recipientarray[0], out of $parent->p_subscriptionList.",2);
	$this->recipientQuery= "AND ( 0 ";

	foreach ($recipientarray AS $key=>$val) {
		if (trim($val)=="") continue;
		$this->recipientQuery.= " OR sitemember.id='$val' ";
		}

	$this->recipientQuery.= " ) ";

	// 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 $this->recipientQuery ";
	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: <b>bcc</b> looks like $bcc. From $query.",1);
	    }
	else berror("comment-save-member-html: member lookup failed on query: $query.",1);

	// email to:
	$to= "$site->name-comment@berylium.org";
	$subject= "[$parent->title] $this->title";

	// construct the other email headers
	$newline= "\r\n";
	$this->headers = "From: $site->title <$site->name@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$_SERVER[SCRIPT_NAME]/'>$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);
    }
else berror("comment-save-member-html: comment already announced on $this->p_announced or member will attempt to login first.",1);

// redirection switch
if ($_POST['authType']=="login") {
    // redirect to comment-login-anonymous-html
    $redirect="$folder->baseUrl/comment-$this->id.html?method=login$session->cgi";
    }
else {
    // redirect back to the parent document, preferably even to the comment just posted...
    $redirect="$parent->baseUrl?method=view&recache=1#comment:$this->id";
    } 

if ($GLOBALS[debug]) {
 print "<b>Updated!</b><br><a href='$redirect'>Click here to continue.</a><br>$redirect";
 }
else {
 header("Location: $redirect");
 exit;
 }


%%end of context%%
