%%document-addCharacter-writer-html%%
2002-12-11 hhc

%%preprocess%%
// we know the originalid, and that it is a character document...
$this->newId= $_GET[newdocumentid];
berror("addCharacter Preprocess: going to add document: $this->newId to scene $this->id ($this->name) with body=$this->body.",1);

// if new is triggered, jump to main cast folder (highest ranked and/or newest with flavor=castfolder) or die
if ($this->newId=="new") {
	$castfolder= new Folder;
	$query= "SELECT obj.* FROM folder AS obj WHERE obj.siteid='$site->id' AND obj.flavor='castfolder' $session->wherestatus $session->wherepublic ORDER BY rank DESC, created DESC";
	$castfolder->selectObject($query);
	if ($castfolder->id=="") {
		berror("You must define at least one folder as being of flavor 'castfolder' in order to add characters.",0);
		exit;
		}
	else {
		$castfolder->getBaseUrl();
		$location= "$castfolder->baseUrl/document-.html?method=create&return=".$folder->baseUrl."document-$this->name.html";
		header("Location: $location");
		exit;
		}
	}

// find default pose...
$pose= new Comment;
$query= "SELECT obj.* FROM comment AS obj WHERE obj.siteid='$site->id' AND parentobjtype='document' AND parentid='$this->newId' $session->wherestatus $session->wherepublic ORDER BY rank DESC, created ASC";
$pose->selectObject($query);
$this->newImageUrl= $pose->title;

// record looks like objtype=document^id=67^position_x=200^position_y=200^position_z=5^dialogue=Ooooohh!^imageUrl=http://galactron/berylium/members/image-woodstock.671d.gif^^
if (substr($this->body,-2)=="^^") {
	$this->body.="^^";
	}
$this->body.= "objtype=document^id=$this->newId^position_x=100^position_y=100^position_z=50^imageUrl=$this->newImageUrl^^";
$this->updateObject();

%%header%%

%%css%%

%%template%%
<table class='bodytable'>
<tr> 
<td>
<p><b>Adding document:$this->newId to $this->title:</b></p>
<img src="$this->newImageUrl">
<p><a href='$folder->baseUrl/document-$this->name.html' target='_top'>Continue...</a></p>
</td>
</tr>
</table>


%%listrow%%

%%nullobject%%

%%footer%%

%%postprocess%%


%%end of context%%
