%%document-view-anonymous-scene%%
hiphopclown.org 
2002-12-21 23:41

%%preprocess%%
// SCENE CONTROLLER
// get info on number of scenes here (sceneTotal)
$this->sceneQuery= "SELECT obj.* FROM document AS obj WHERE obj.folderid='$this->folderid' AND obj.flavor='Scene' $session->statuswhere $session->publicwhere ORDER BY rank DESC, created ASC ";
$firstscene= new Document;
berror("SceneControl: <b>looking up scene list here</b>",1);
$sceneArray= $firstscene->selectObject($this->sceneQuery);
berror("SceneControl: <b>found $firstscene->listsize scenes</b>.",1);
$this->total= $firstscene->listsize;

// which scene is being displayed? (sceneOffset)
$this->sceneArrayKey= -1;
foreach ($sceneArray AS $key=>$myScene) {
	berror("SceneControl looking at sceneArray[$key], named $myScene[name]. ($object->name)",1);
	if ($myScene['id']==$this->id) {
		berror("SceneControl <b>MATCH</b> on $key.",1);
		$this->sceneArrayKey= "$key";
		break;
		}
	}

// find last, first, previous and next scene names
$this->offset= $this->sceneArrayKey + 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= "Scene";

// headline fix if only title, and vice-versa
if ($this->title=="" && $this->headline=="") $this->title= "Untitled ($this->name)";
elseif ($this->title=="") $this->title= $this->headline;
elseif ($this->headline=="") $this->headline= $this->title;


// 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>Scene 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("Scene Render: found NULL objectref, continuing.",1);
		$objectindex++;
		continue;
		}

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

	// create a berylium object and do a database lookup
	$command= "\$myObject= new ".ucfirst($myObjectVars['objtype']).";";
	eval($command);
	$query= "SELECT obj.* FROM $myObjectVars[objtype] AS obj WHERE obj.siteid='$site->id' AND obj.id='$myObjectVars[id]' $session->wherestatus $session->wherepublic ";
	$myObject->selectObject($query);
	if ($myObject->id=="") {
		berror("Scene 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("Scene Render: preprocessing $myObject->flavor$myObject->id ($myObject->title).",1);
	$myObject->beryliumToHtml();
	$myObject->getRuntimeVars();
	if ($myRow=="" || $myRow=="odd") {
		$myObject->rowclass="oddrow";
		$myRow= "even";
		}
	else {
		$myObject->rowclass="evenrow";
		$myRow= "odd";
		}

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

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

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

	// image process
	$myObject->imageUrl= $myObjectVars['imageUrl'];
	berror("Scene Render: looking at image=$myObject->imageUrl.",1);
	if ($image= getimagesize($myObject->imageUrl)) {
		$width= $image[0];
		$height= $image[1];

		$myObject->width= $width."px";
		$myObject->numericwidth= $width;
		$myObject->height= $height."px";
		$myObject->numericheight= $height;
		}

	// POSE SELECT
	if ($this->itemOwner || $this->itemEditor) {
		$query2= "SELECT obj.* FROM comment AS obj WHERE obj.parentobjtype='document' AND obj.parentid='$myObject->id' AND obj.flavor='Pose' $session->wherestatus $session->wherepublic ";
		if ($result2= @mysql_query($query2)) {
			$myObject->poseSelect= "<select name='$myObject->divId-imageUrl'>\n";
			while ($array2= @mysql_fetch_array($result2)) {
				$title= $array2['title'];
				$description= htmlentities($array2['description']);
				if ($title==$myObject->imageUrl) $selected= "selected";
				else $selected= "";
				$myObject->poseSelect.= "<option value='$title' $selected>$description</option>\n";
				}
			$myObject->poseSelect.= "</select>";
			}
		}

	// 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= "";
		}

	// OBJECT RENDER
	if ($this->itemOwner || $this->itemEditor) {
		$this->dblClickControls= "onDblClick=\"window.location='#controls';\"";
		$this->objects.= "
				<div id=\"$myObject->divId\" title=\"Click and drag to move; Double-click for controls.\"
					style=\"position: absolute; left: $myObject->left; top: $myObject->top; z-index: $myObject->zindex; width: $myObject->width; height: $myObject->height; border: 1px; border-style: none; \"
					onDblClick=\"window.location='#form-$myObject->divId';\"
					onMouseOver=\"MM_dragLayer('$myObject->divId','',0,0,$myObject->numericwidth,$myObject->numericheight,false,false,-1,-1,-1,-1,false,false,0,'',false,'');\">
					<a name=\"anchor-$myObject->divId\"> </a>
					<img src=\"$myObject->imageUrl\" width=\"$myObject->numericwidth\" height=\"$myObject->numericheight\" border=0>
					$myObject->dialogTag
				</div>
				";

		// OBJECT CONTROLS
		$this->objectControls.= "
		<tr class='$myObject->rowclass'>
			<td colspan=\"3\"><a name=\"form-$myObject->divId\"> </a>
				<span class='objFlavor'>$myObject->flavor:<br></span>
				<span class='objTitle'>$myObject->title</span> ( <a href='$myObject->uri' target='_top'>Original Character</a> ) ( <a href='$this->baseUrl?method=removeCharacter&remove=$objectindex'>Remove from Scene</a> )
			</td>
		</tr>
		<tr class='$myObject->rowclass'>
			<td align=\"center\" valign=\"middle\" rowspan=\"4\">
				<input type='hidden' name='object[$objectindex]' value='1'>
				<input type='hidden' name='$myObject->divId-objtype' value='$myObject->objtype'>
				<input type='hidden' name='$myObject->divId-id' value='$myObject->id'>
				<img src=\"$myObject->imageUrl\"><br />
				<br />
				Pose:
				$myObject->poseSelect<br />
				<br />
				<input type=\"submit\" name=\"submit\" value=\"Save Settings\" class='buttonstyle'/>
			</td>
			<td align=\"right\" valign=\"top\">Position:</td>
			<td valign=\"top\">
				<input name=\"$myObject->divId-position_x\" type=\"text\" size=\"3\" onchange=\"myUpdater('$myObject->divId','$myObject->divId-position_x','left');\" value=\"$myObject->position_x\" /> pixels over<br />
				<input name=\"$myObject->divId-position_y\" type=\"text\" size=\"3\" onchange=\"myUpdater('$myObject->divId','$myObject->divId-position_y','top');\" value=\"$myObject->position_y\" /> pixels down<br />
				<input name=\"$myObject->divId-position_z\" type=\"text\" size=\"3\" onchange=\"myUpdater('$myObject->divId','$myObject->divId-position_z','zIndex');\" value=\"$myObject->position_z\" /> layer order (0 is bottom)
			</td>
		</tr>
		<tr class='$myObject->rowclass'>
			<td align=\"right\" valign=\"top\">Dialog:</td>
			<td valign=\"top\"><textarea name=\"$myObject->divId-dialog\" cols=\"20\" rows=\"4\" class='dialogTextArea'>$myObject->dialog</textarea></td>
		</tr>
		<tr class='$myObject->rowclass'>
			<td align=\"right\" valign=\"top\">Dialog offset:</td>
			<td valign=\"top\"><input name=\"$myObject->divId-dialogOffset\" type=\"text\" size=\"3\" value=\"$myObject->dialogOffset\" /> pixels up</td>
		</tr>
		<tr class='$myObject->rowclass'>
			<td align=\"right\" valign=\"top\">Dialog type:</td>
			<td valign=\"top\">
				<input name=\"$myObject->divId-dialogAlign\" type=\"radio\" class='radiostyle' value='left' $myObject->dAleft> left &nbsp;
				<input name=\"$myObject->divId-dialogAlign\" type=\"radio\" class='radiostyle' value='right' $myObject->dAright> right &nbsp;
				<input name=\"$myObject->divId-dialogAlign\" type=\"radio\" class='radiostyle' value='add' $myObject->dAadd> addendum
			</td>
		</tr>";
		}
	else {
		// next link
		if ($this->offset<$this->total && $this->foundOnOffset) {
			$this->singleClickAdvance= "onClick=\"window.location='".$folder->baseUrl."document-.scene?offset=$this->offset&total=$this->total';\" title='Click to advance scene.'";
			}
		elseif ($this->offset==$this->total && $this->foundOnOffset) {
			$this->singleClickAdvance= "onClick=\"window.location='".$folder->baseUrl."document-.scene?offset=0&total=$this->total';\"  title='Click to loop back to first scene.'";
			}
		$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>
					<img src=\"$myObject->imageUrl\" width=\"$myObject->numericwidth\" height=\"$myObject->numericheight\" border=0>
					$myObject->dialogTag
				</div>
				";
		}

	unset($myObject, $myObjectVars, $query, $query2);
	$objectindex++;
	}

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

// prevtag / nexttag logic
if ($this->offset!=1) {
	$this->prevtag= "<a href='".$folder->baseUrl."document-".$sceneArray[$previous]['name'].".html' target='_top'>&laquo; Prev</a>&nbsp;&nbsp;";
	}
if ($this->offset==1) {
	// not showing jump-to-last
	//$this->prevtag= "<a href='".$folder->baseUrl."document-".$sceneArray[$last]['name'].".html' target='_top'>Last &raquo</a>&nbsp;&nbsp;";
	$this->prevtag= "";
	}
if ($this->offset<$this->total) {
	$this->nexttag= "&nbsp;&nbsp;<a href='".$folder->baseUrl."document-".$sceneArray[$next]['name'].".html' target='_top'>Next &raquo;</a>";
	}
if ($this->offset==$this->total) {
	$this->nexttag= "&nbsp;&nbsp;<a href='".$folder->baseUrl."document-".$sceneArray[0]['name'].".html' target='_top'>&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->infoBottom= "5px";
	
berror("<b>Scene Render: FINISHED</b>.",1);
if ($this->itemEditor || $this->itemOwner) $this->showNull= 1;

%%header%%


%%css%%
.boothtable	{ background-color: #f9f9fb;
			border: 3px; border-color: #0e47b2; border-style: solid;
			color: #223344;
			font-family: Tahoma, Geneva, sans-serif; font-size: 12px; line-height: 18px;
			width: $this->backgroundwidth;
			}
.boothtable A { color: #135b9f; }
.sceneInfo { font-family: Arial, Helvetica, sans-serif; font-size: 10px; line-height: 14px; color: #ffffff; text-align: center; }
.sceneInfo A { color: $this->infoColor; font-weight: bold; }


%%template%%
<a name="top"> </a>
<img src="/bicons/spacer.gif" width="$this->bgnumericwidth" height="$this->bgnumericheight" border=0>
<div id='background' style='position: absolute; left: 0px; top: 0px; width: $this->backgroundwidth; height: $this->backgroundheight; z-index:1; background-color: #333333; background-image: url($folder->p_background); background-position: center center;' onDblClick="window.location='#controls';">
	<div id='sceneInfo' class='sceneInfo' 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>
</div>
$this->objects
<br />

%%listrow%%


%%nullobject%%
<a name="top"> </a>
<img src="/bicons/spacer.gif" width="$this->bgnumericwidth" height="$this->bgnumericheight" border=0>
<div id='background' style='position: absolute; left: 0px; top: 0px; width: $this->backgroundwidth; height: $this->backgroundheight; z-index:1; background-color: #333333; background-image: url($folder->p_background); background-position: center center;' $this->dblClickControls $this->singleClickAdvance>
	<div id='sceneInfo' class='sceneInfo' 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>
</div>
$this->objects
<br /><a name="controls">&nbsp;</a>
<br />
<table class="boothtable"  cellpadding="8">
	<tr>
		<td valign='top'>
			<span class='objTitle'>Players/Props Controls:</span> ( <a href="$folder->baseUrl/document-$this->name.html?method=edit" target="_top">Edit this Scene</a> ) ( <a href="$folder->baseUrl/document-$this->name.html?method=duplicate" target="_top">Duplicate this Scene</a> )
			<p class='objInfo'><a href="#top">Return to the scene.</a> You can also double-click to switch between scene and controls.</p>
			{list:SELECT obj.* FROM document AS obj WHERE obj.flavor='Character';characterSelect}
			<form name="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="#controls">Top of Controls</a> or <a href="#top">Return to the scene.</a></p>
			<img src="/bicons/spacer.gif" width=430 height=1>
		</td>
	</tr>
</table>
<br />
<br />&nbsp;

%%footer%%


%%postprocess%%


%%end of context%%
