%%comment-list-anonymous-scene%%
$Date: 2003/02/18 00:23:51 $

%%preprocess%%
// FRAME CONTROLLER
// get info on number of frames here (frameTotal)
$this->frameQuery= "SELECT obj.* FROM comment AS obj WHERE obj.folderid='$this->folderid' AND obj.flavor='Frame' AND obj.parentobjtype='$object->objtype' AND obj.parentid='$object->id' $session->statuswhere $session->publicwhere ORDER BY rank DESC, created ASC ";
$firstframe= new Comment;
berror("FrameControl: <b>looking up frame list here</b>",1);
$frameArray= $firstframe->selectObject($this->frameQuery);
berror("FrameControl: <b>found $firstframe->listsize frames</b>.",1);
$this->total= $firstframe->listsize;

// which frame is being displayed? (frameOffset)
$this->frameArrayKey= -1;
foreach ($frameArray AS $key=>$myFrame) {
	berror("FrameControl looking at frameArray[$key], with id $myFrame[id], for match on $this->id.",1);
	if ($myFrame['id']==$this->id) {
		berror("FrameControl <b>MATCH</b> on $key.",1);
		$this->frameArrayKey= "$key";
		break;
		}
	}

// find last, first, previous and next frame names
$this->offset= $this->frameArrayKey + 1;

// OBJECT FORMATTING
// format the object for display
$cleanbody= $this->body;
$this->beryliumToHtml();
$this->getRuntimeVars();
$this->applyPolicy();

// convert generic flavor to objtype:
if ($this->flavor=="Generic") $this->flavor= "Frame";

// title fixing
if ($this->title=="") $this->title= "Frame #$this->id";


// ROOM SETTINGS
berror("Getting imagesize on $folder->p_background now...",1);
if ($background= getimagesize($folder->p_background)) {
	berror("Got it.",1);
	$width= $background[0];
	$height= $background[1];

	$targetwidth= 630;
	$targetheight= 430;

	if ($width>$targetwidth) {
		//$height= $height * ($targetwidth/$width);
		$width= $targetwidth;
		}
	if ($height>$targetheight) {
		//$width= $width * ($targetheight/$height);
		$height= $targetheight;
		}

	$this->backgroundwidth= $width."px";
	$this->bgnumericwidth= $width;
	$this->backgroundheight= $height."px";
	$this->bgnumericheight= $height;
	}


// SCENE PARSE $this->body into characters, props, whathaveya
// 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^^
berror("<b>Frame Render: STARTING</b> with $cleanbody.",1);
$myObjectArray= explode("^^",$cleanbody);
$objectindex=0;
foreach ($myObjectArray AS $key=>$myObjectRef) {
	
	// PREPROCESS and cleanup
	$myObjectRef= trim($myObjectRef);
	if ($myObjectRef=="") {
		berror("Frame Render: found NULL objectref, continuing.",1);
		$objectindex++;
		continue;
		}

	// break out the object vars
	$myObjectVars= bunpack($myObjectRef);
	if ($myObjectVars['objtype']=="" || $myObjectVars['id']=="") {
		berror("Frame Render: found NULL objectref on bunpack, continuing: $myObjectRef.",1);
		$objectindex++;
		continue;
		}
	berror("<b>Frame Render: FOUND</b> $myObjectVars[objtype] #$myObjectVars[id], will attempt to render it. ($session->wherestatus)",1);

	// create a berylium object and do a database lookup
	if ($myObjectVars['objtype']=="label") {
		$myObject= new Document;
		$myObject->flavor= "Label";
		$myObject->label= $myObjectVars['label'];
		$label= bHtml($myObjectVars['label']);
		}
	elseif ($myObjectVars['objtype']=="googleimage") {
		$myObject= new Document;
		$myObject->objtype= "googleimage";
		$myObject->id= 0;
		$myObject->flavor= "GoogleImage";
		$myObject->label= $myObjectVars['label'];
		$label= bparsebml("[googleimage:$myObjectVars[label]]");
		$myObject->controlsPose= $label;

		$width= 100;
		$height= 100;
		$myObject->width= $width."px";
		$myObject->numericwidth= $width;
		$myObject->height= $height."px";
		$myObject->numericheight= $height;
		$myObject->htmlUrl= $myObject->label;
		}
	else {
		$command= "\$myObject= new ".ucfirst($myObjectVars['objtype']).";";
		eval($command);
		$myObject->selectObjectById($myObjectVars['id']);
		if ($myObject->id=="") {
			berror("Frame Render: found no matching object in the database. Or at least none available to this user.",1);
			$objectindex++;
			continue;
			}

		// format the object for display
		berror("Frame Render: preprocessing $myObject->flavor$myObject->id ($myObject->title).",1);
		//$myObject->beryliumToHtml();
		//$myObject->getRuntimeVars();
		//$myObject->getBaseUrl();
		}

	// alternating rows
	if ($myRow=="" || $myRow=="odd") {
		$myObject->rowclass="oddrow";
		$myRow= "even";
		}
	else {
		$myObject->rowclass="evenrow";
		$myRow= "odd";
		}

	// divid for javascript
	$myObject->divId= "object$objectindex";

	// positioning and size info
	$myObject->position_x= $myObjectVars['position_x'];
	$myObject->position_y= $myObjectVars['position_y'];
	$myObject->position_z= $myObjectVars['position_z'];
	$myObject->size_w= $myObjectVars['size_w'];
	$myObject->size_h= $myObjectVars['size_h'];

	$myObject->left= $myObject->position_x."px";
	$myObject->top= $myObject->position_y."px";
	$myObject->zindex= $myObject->position_z;

	// special processing if this is a Character
	$myObject->isCharacter= $myObjectVars['isCharacter'];
	$myObject->poseid= $myObjectVars['poseid'];
	if ($myObject->poseid!="") {
		// find pose
		berror("Frame Render: pose is image:$myObject->poseid.",1);

		// POSE RENDER
  		$myObject->poseObj= new Image;
		$myObject->poseObj->selectObjectById($myObject->poseid);
		if ($myObject->poseObj->id!="") {
			// 0 returns value to normal size
			if (!$myObject->size_w) $myObject->size_w= $myObject->poseObj->width;
			if (!$myObject->size_h) $myObject->size_h= $myObject->poseObj->height;

			// proportion
			$myObject->poseObj->proportion($myObject->size_w,$myObject->size_h,1);

			// other formatting
			$myObject->poseObj->getBaseUrl();
			$myObject->imageUrl= $myObject->poseObj->uri;
			$width= $myObject->poseObj->width;
			$height= $myObject->poseObj->height;
			$myObject->width= $width."px";
			$myObject->numericwidth= $width;
			$myObject->height= $height."px";
			$myObject->numericheight= $height;

			// imagetag
			$imageTag="<img src=\"$myObject->imageUrl\" width=\"$myObject->numericwidth\" height=\"$myObject->numericheight\" border=0>";
			}

		if ($myObject->isCharacter==1) {
			// dialog direction
			$myObject->dialogAlign= $myObjectVars['dialogAlign'];
			$dAdialogAlign= "dA".$myObject->dialogAlign;
			$myObject->{$dAdialogAlign}= "checked=1";

			// dialog balloon
			if (trim($myObjectVars['dialog'])!="") {
				$myObject->dialogOffset= $myObjectVars['dialogOffset'];
				$dialogOffset= $myObject->numericheight + $myObject->dialogOffset;
				$myObject->dialog= $myObjectVars['dialog'];
				$dialog= bHtml($myObject->dialog);
				if ($myObject->dialogAlign=="left" || $myObject->dialogAlign=="") {
					// left
					$myObject->dialogTag= "
					<div id='dialog-$myObject->divId'
						style='position: absolute; width: 200px; z-index: ".($myObject->zindex+1)."; left: -30px; bottom: $dialogOffset; border: 0px; padding: 0px;' >
						<table width=200 border='0' cellpadding='0' cellspacing='0'>
							<tr>
								<td><img src='/bicons/dialog/nw.gif' width=15 height=15></td>
								<td><img src='/bicons/dialog/n-l.gif' width=27 height=15></td>
								<td style='background-image: url(/bicons/dialog/n.gif);'><img src='/bicons/dialog/spacer.gif' width=141 height=15></td>
								<td><img src='/bicons/dialog/ne.gif' width=17 height=15></td>

							</tr>
							<tr>
								<td style='background-image: url(/bicons/dialog/w.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
								<td COLSPAN=2 align=center valign=middle  bgcolor='#ffffff'><div class='dialog'>$dialog</div></td>
								<td style='background-image: url(/bicons/dialog/e.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
							</tr>
							<tr>

								<td><img src='/bicons/dialog/sw.gif' width=15 height=41></td>
								<td><img src='/bicons/dialog/s-l.gif' width=27 height=41></td>
								<td style='background-image: url(/bicons/dialog/s.gif);'><img src='/bicons/dialog/spacer.gif' width=141 height=41></td>
								<td><img src='/bicons/dialog/se.gif' width=17 height=41></td>
							</tr>
						</table>
					</div>";
					}
				elseif ($myObject->dialogAlign=="add") {
					// add
					$myObject->dialogTag= "
						<div id='dialog-$myObject->divId'
							style='position: absolute; width: 150px; z-index: ".($myObject->zindex+1)."; left: -30px; bottom: $dialogOffset; border: 0px; padding: 0px;' >
							<table width=150 border='0' cellpadding='0' cellspacing='0'>
								<tr>
									<td><img src='/bicons/dialog/nw.gif' width=15 height=15></td>
									<td style='background-image: url(/bicons/dialog/n.gif);'><img src='/bicons/dialog/spacer.gif' width=30 height=15></td>
									<td style='background-image: url(/bicons/dialog/n.gif);'><img src='/bicons/dialog/spacer.gif' width=91 height=15></td>
									<td><img src='/bicons/dialog/ne.gif' width=17 height=15></td>

								</tr>
								<tr>
									<td style='background-image: url(/bicons/dialog/w.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
									<td COLSPAN=2 align=center valign=middle  bgcolor='#ffffff'><div class='dialog'>$dialog</div></td>
									<td style='background-image: url(/bicons/dialog/e.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
								</tr>
								<tr>

									<td><img src='/bicons/dialog/sw.gif' width=15 height=41></td>
									<td style='background-image: url(/bicons/dialog/s.gif);'><img src='/bicons/dialog/spacer.gif' width=30 height=41></td>
									<td style='background-image: url(/bicons/dialog/s.gif);'><img src='/bicons/dialog/spacer.gif' width=91 height=41></td>
									<td><img src='/bicons/dialog/se.gif' width=17 height=41></td>
								</tr>
							</table>
						</div>";
						}
				else {
					// right
					$myObject->dialogTag= "
					<div id='dialog-$myObject->divId'
						style='position: absolute; width: 200px; z-index: ".($myObject->zindex+1)."; right: -30px; bottom: $dialogOffset; border: 0px; padding: 0px;' >
						<table width=200 border='0' cellpadding='0' cellspacing='0'>
							<tr>
								<td><img src='/bicons/dialog/nw.gif' width=15 height=15></td>
								<td style='background-image: url(/bicons/dialog/n.gif);'><img src='/bicons/dialog/spacer.gif' width=141 height=15></td>
								<td><img src='/bicons/dialog/n-r.gif' width=27 height=15></td>
								<td><img src='/bicons/dialog/ne.gif' width=17 height=15></td>

							</tr>
							<tr>
								<td style='background-image: url(/bicons/dialog/w.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
								<td COLSPAN=2 align=center valign=middle  bgcolor='#ffffff'><div class='dialog'>$dialog</div></td>
								<td style='background-image: url(/bicons/dialog/e.gif);'><img src='/bicons/dialog/spacer.gif' width=15 height=5></td>
							</tr>
							<tr>

								<td><img src='/bicons/dialog/sw.gif' width=15 height=41></td>
								<td style='background-image: url(/bicons/dialog/s.gif);'><img src='/bicons/dialog/spacer.gif' width=141 height=41></td>
								<td><img src='/bicons/dialog/s-r.gif' width=27 height=41></td>
								<td><img src='/bicons/dialog/se.gif' width=17 height=41></td>
							</tr>
						</table>
					</div>";
					}
				$dialogOffset= "";
				} // end if dialog
			} // end if character
		} // end if poseid

	// OBJECT RENDER

	// next link
	if ($this->offset<$this->total && $this->foundOnOffset) {
		$this->singleClickAdvance= "onClick=\"window.location='".$folder->baseUrl."document-.frame?offset=$this->offset&total=$this->total';\" title='Click to advance frame.'";
		}
	elseif ($this->offset==$this->total && $this->foundOnOffset) {
		$this->singleClickAdvance= "onClick=\"window.location='".$folder->baseUrl."document-.frame?offset=0&total=$this->total';\"  title='Click to loop back to first frame.'";
		}
	$this->objects.= "
			<div id=\"$myObject->divId\" title=\"$myObject->title\"
				style=\"position: absolute; left: $myObject->left; top: $myObject->top; z-index: $myObject->zindex; width: $myObject->width; height: $myObject->height; border: 1px; border-style: none; \">
				<a name=\"anchor-$myObject->divId\"> </a>
				<a href='$myObject->htmlUrl' target='_top'>$imageTag</a>
				$myObject->dialogTag
				$label
			</div>
			";


	unset($myObject, $myObjectVars, $query, $query2, $pose, $posequery, $label, $imageTag);
	$objectindex++;
	}

// SCENE CONTROL PART II
// first is 0
$previous= $this->frameArrayKey - 1;
$next= $this->frameArrayKey + 1;
$last= $this->total - 1;

// prevtag / nexttag logic
if ($this->offset!=1) {
	$this->prevtag= "<a href='#' onClick='prevFrame();'>&laquo; Prev</a>&nbsp;&nbsp;";
	}
if ($this->offset==1) {
	// not showing jump-to-last
	//$this->prevtag= "<a href='$object->baseUrl?frameid=".$frameArray[$last]['id']."'>Last &raquo</a>&nbsp;&nbsp;";
	$this->prevtag= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
	}
if ($this->offset<$this->total) {
	$this->nexttag= "&nbsp;&nbsp;<a href='#' onClick='nextFrame();'>Next &raquo;</a>";
	}
if ($this->offset==$this->total && $this->total>1) {
	$this->nexttag= "&nbsp;&nbsp;<a href='#' onClick='nextFrame();'>&laquo; Restart &raquo;</a>";
	}
	
// SCENEINFO COLOR
if ($folder->p_infoColor!="") $this->infoColor= $folder->p_infoColor;
else $this->infoColor= "white";

// INFO POSITION
$bgcenter= $this->bgnumericwidth / 2;
$this->infoLeft= ($bgcenter - 90)."px";
$this->infoTop= ($this->bgnumericheight-20)."px";

berror("<b>Frame Render: FINISHED</b>.",1);
//if ($this->itemEditor || $this->itemOwner) $this->showNull= 1;


// MEMBER ADD TAG
if ( $sitemember->role!="anonymous" && $object->insert ) {
	$create= " or <a href='$folder->baseUrl/document-.scene?method=stage1'>Create your own</a>";
	}
if ($sitemember->role!="anonymous" && $object->update ) {
	$this->editTag= "<a href='$object->baseUrl?frameid=$this->id'>Switch to Edit Mode</a>";
	$this->memberAddTag= "<a href='$object->baseUrl?method=mailto'>Email your scene to a friend!</a>";
	}
else {
	$this->editTag= "<a href='$site->baseUrl'>$site->title</a>";
	$this->memberAddTag= "<a href='$object->baseUrl?method=mailto'>Email this scene</a>$create!";
	}


%%header%%


%%css%%


%%template%%
<!-- frame:$this->id -->
<div id='frame$this->offset' style='visibility: hidden'>
	<div id='frameSwitch' class='frameInfo' style='position: absolute; width: 180px; z-index: 1; left: 10px; top: $this->infoTop; border: 1px; padding: 0px; border-style: none; text-align: left;' >
		$this->editTag
	</div>
	<div id='frameInfo' class='frameInfo' style='position: absolute; width: 180px; z-index: 1; left: $this->infoLeft; top: $this->infoTop; border: 1px; padding: 0px; border-style: none;' >
		$this->notFound
		$this->prevtag $this->offset of $this->total $this->nexttag
	</div>
	<div id='frameStage' class='frameInfo' style='position: absolute; width: 180px; z-index: 2; right: 10px; top: $this->infoTop; border: 1px; padding: 0px; border-style: none; text-align: right;' >
		$this->memberAddTag
	</div>
	$this->objects
</div>

%%listrow%%


%%nullobject%%
<!-- frame:$this->id (editor or null) -->
<div id='frame$this->id'>
	<div id='frame$this->id-frameInfo' class='frameInfo' style='position: absolute; width: 180px; z-index: 1; left: $this->infoLeft; bottom: $this->infoBottom; border: 1px; padding: 0px; border-style: none;' >
		$this->notFound
		$this->prevtag $this->offset of $this->total $this->nexttag
	</div>
	$this->objects
	<br /><a name="frame$this->id-controls">&nbsp;</a>
	<br />
	<table class="boothtable"  cellpadding="8">
		<tr>
			<td valign='top'>
				<span class='objTitle'>Players/Props Controls:</span> ( <a href="$folder->baseUrl/comment-$this->id.html?method=edit" target="_top">Edit this Frame</a> ) ( <a href="$folder->baseUrl/comment-$this->id.html?method=duplicate" target="_top">Duplicate this Frame</a> )
				<p class='objInfo'><a href="#top">Return to the frame.</a> You can also double-click to switch between frame and controls.</p>
				{list:SELECT obj.* FROM document AS obj WHERE obj.flavor='Character';characterSelect}
				<form name="frame$this->id-objectControls" action="$this->baseUrl?method=save$session->cgi" method="POST" onDblClick="window.location='#top';">
				<input type="hidden" name="id" value="$this->id">
				<table class="edittable">
				$this->objectControls
				</table>
				</form>
				<p class='info'>End of Controls. <a href="#frame$this->id-controls">Top of Controls</a> or <a href="#top">Return to the frame.</a></p>
				<img src="/bicons/spacer.gif" width=430 height=1>
			</td>
		</tr>
	</table>
</div>


%%footer%%


%%postprocess%%


%%end of context%%

