Login   Register  
PHP Classes
elePHPant
Icontem

File: SoftMoon.rainbowmaker.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Joseph  >  Rainbow Maker  >  SoftMoon.rainbowmaker.php  >  Download  
File: SoftMoon.rainbowmaker.php
Role: Auxiliary data
Content type: text/plain
Description: HTML user interface
Class: Rainbow Maker
Create transparent gradient images
Author: By
Last change: last edit (using this site's edit file function) was encoded in ASCII but should have been UTF-8
Date: 2012-03-05 06:19
Size: 60,674 bytes
 

Contents

Class file image Download
<?php /* rainbowmaker.php version BETA 4.1 release 1.0  1-12-2012
					written by and Copyright © 2011, 2012 Joe Golembieski, Softmoon-Webware

		This program is free software: you can redistribute it and/or modify
		it under the terms of the GNU General Public License as published by
		the Free Software Foundation, either version 3 of the License, or
		(at your option) any later version.
		The original copyright information must remain intact.

		This program is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
		GNU General Public License for more details.

		You should have received a copy of the GNU General Public License
		along with this program.  If not, see <http://www.gnu.org/licenses/>   */

//  character encoding: UTF-8 UNIX   tab-spacing: 2   word-wrap: no   standard-line-length: 120

$exectime=ini_set('max_execution_time', '300');  // 5 minutes
session_start();

if (!defined('DIR_SEP'))  {
	if (stripos(php_uname('s'), 'Win')===FALSE)    // Mac OS/LINUX/UNIX directory separator
		define('DIR_SEP', "/");
	else    // MS Windows directory separator
		define('DIR_SEP', "\\");  }

set_include_path(get_include_path()
	.PATH_SEPARATOR.'PHP_toolbucket'.DIR_SEP.'SoftMoon'.DIR_SEP.'rainbow-maker'.DIR_SEP
	.PATH_SEPARATOR.'PHP_toolbucket'.DIR_SEP.'SoftMoon'.DIR_SEP
	);

	define ('CHECK_PASSWORD', FALSE); //for installation on a public server, you may want to activate the password feature.
	define ('PW_DB', 'PW/');   // this is the folder where password generator files are kept
	define ('FONTS_FOLDER', 'Fonts/');   // for use with the password generator ...and future additions...

	define ('IMAGE_FOLDER', 'RainbowImages/');  // this should be a publicly available folder
	define ('UPLOAD_FOLDER', 'uploadedImages/');  //  this should be a non-public 'forbidden access' folder if installed on a public server, and should never have PHP parse any files within.  PHP may be hidden in the comment fields of JPGs and PNGs, and if parsed, PHP may then call the file (self) as an executable, with unstoppable malicious code hidden in the picture itself.  By default, PHP will -not- parse image files, but as it -may- be enabled by file extension by the host system administrator, disabling folder access is best practice.
	define ('UPLOAD_DEST', UPLOAD_FOLDER.session_id().'.');  //  this is the internally used upload file prefix.
	define ('KEEP_FOLDER_CLEAN', FALSE);  // If TRUE, all images in IMAGE_FOLDER, and unused images in UPLOAD_FOLDER,
																			 //   older than LINGER minues will be deleted (for use on a public server).
	define ('DUMP_UPLOADS', FALSE);  // if TRUE, no uploads will be kept
	define ('LINGER', 20);  // minimum number of minutes to keep a created rainbow and uploaded files.

	define ('SHOW', 1);  // gallery images may be shown if requested  (DO NOT CHANGE THIS VALUE)
	define ('ACCESS', 2);  // gallery images may be directly used as background or foreground images  (DO NOT CHANGE THIS VALUE)
	define ('SAVETO', 4);  // user images may be saved to the gallery  (DO NOT CHANGE THIS VALUE)
	define ('PASSWORD', 8);  // saving to the gallery requires a password  (DO NOT CHANGE THIS VALUE)
	define ('ALLOW_GALLERY', (SHOW | ACCESS | SAVETO)); //  | PASSWORD      0
	define ('GALLERY_FOLDER', 'RainbowGallery/');  // this should be a publicly available folder
	define ('GALLERY_PASSWORD', 'PHP rocks');

	define ('MAX_GRAFK_SIZE', PHP_INT_MAX);  //  default is 500*500

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 //EN"	"http://www.w3.org/TR/HTML4.1/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name='version' content='BETA 4.1 / Release 1.0' />
<meta name='author' content='Joe Golembieski, SoftMoon-WebWare' />
<meta name='copyright' content='Copyright © 2011, 2012 by the author' />
<meta name='x-generator' content='tswebeditor.tigris.org' />
<meta name='x-generator' content='tswebeditor.tigris.org' />
<meta name='description' content='Create your own multi-colored rainbow-transparency gradients in multiple shapes using this PHP powered tool.' />
<title>PHP powered .png Rainbow Maker</title>
<link rel="stylesheet" type="text/css" media="screen, projection" href="JS_toolbucket/freqdec-fd-slider-01084d3/css/fd-slider.css" />
<link rel='stylesheet' type='text/css' media="screen, projection" href='SoftMoon.rainbowmaker.css' />
<script type='text/javascript' src="JS_toolbucket/freqdec-fd-slider-01084d3/js/fd-slider.js"></script>
<script type='text/javascript' src='JS_toolbucket/SoftMoon.FormFieldGenie.js'></script>
<script type='text/javascript' src='JS_toolbucket/Animator.js'></script>
<script type='text/javascript' src='SoftMoon.rainbowmaker.js'></script>
<!-- [if IE 6]>
<style type='text/css'>
div#color_picker_wrap  {
	position: absolute; }
</style>
<![endif] -->
</head>
<body onload='atLoad();'><!--  div id='tester'></div><div id='tester2'></div  -->
<script type='text/javascript'>//<![CDATA[
if (navigator.userAgent.match( /Firefox/ ))  {
	document.write(
"<div id='burning_bronto'>Sorry you, you’re using Mozilla’s “burning brontosaurus-out-of-water” Firefox.&nbsp;\n" +
"Chances are, you will have a poor browsing experience on this site.&nbsp;\n" +
"A modern browser (that supports standards in line with all the other modern browsers) is recommended.&nbsp;\n" +
"Try:\n" +
"<ul>\n" +
"<li>Opera’s desktop browser</li>\n" +
"<li>Google’s Chrome</li>\n" +
"<li>Apple’s Safari</li>\n" +
"</ul>\n" +
"</div>\n" )  }
//]]></script>
<!-- and NO I'm not going to go out of my way, wasting my time, adding superfluous markup and workarounds
			to support these browsers.  THEY need to be fixed, not the other way around.
			Unless, of course, you want to pay me for a commersial installation of this ☻☻☻☻☻☻☻ -->
<!-- [if lt IE 8]>
<div id='ms_internet_exploder'>Sorry you, you’re using Microsoft’s Internet Exploder.&nbsp;
Chances are, you will have a poor browsing experience on this site.&nbsp;
A modern browser (that supports standards defined in the mid-1990’s) is recommended.&nbsp;
Try:
<ul>
<li>Opera’s desktop browser</li>
<li>Google’s Chrome</li>
<li>Apple’s Safari</li>
</ul>
Note: avoid Mozilla’s Firefox - it is also unable to render this page correctly.
</div>
<![endif] -->

<h1><a href='SoftMoon.Rainbow-Maker_instructions.htm#content'>Rainbow Maker<span>by SoftMoon WebWare</span><img src='images/SoftMoonWebWare.gif' alt='' /></a></h1><br />
<?php

	if (!isset($_SESSION['picName']))  $_SESSION['picName']=newPicName();

	set_error_handler(create_function('$errno, $errstr, $errfile, $errline',
			'throw new ErrorException($errstr, 255, $errno, basename($errfile), $errline);  return true;'),
		E_ALL & ~E_NOTICE);

	try {
	if (CHECK_PASSWORD) {require "Password.php";  $Password=new Password;}
	if (!is_dir(IMAGE_FOLDER))  mkdir(IMAGE_FOLDER);
	if (CHECK_PASSWORD  and  !is_dir(IMAGE_FOLDER.'PWs'))  mkdir(IMAGE_FOLDER.'PWs');
	if (!is_dir(UPLOAD_FOLDER))  mkdir(UPLOAD_FOLDER);
	if (ALLOW_GALLERY  and  !is_dir(GALLERY_FOLDER))  mkdir(GALLERY_FOLDER);
	if (ALLOW_GALLERY)  require_once 'Rainbow.Builder.php';
	}
	catch (ErrorException $e)  {echo "<h4>filesystem error:</h4>$e\n</body></html>\n";  exit;}

	if (isset($_POST['show']))  { //process new Rainbow image

		if (!isset($_SESSION['uploads'])  or  !is_array($_SESSION['uploads']))  $_SESSION['uploads']=array();

		try {

		if (CHECK_PASSWORD  and  !$Password->check($_POST['password'], PW_DB))
			throw new Exception('Password does not match or has expired.');

		require_once 'file_path_exists.php';
		require_once 'include_modules.php';
		require_once 'Rainbow.Builder.php';
		require_once 'Rainbow~pluginShapes.php';
		if (file_path_exists('colorcharts'))  include_modules('colorcharts');
		require_once 'getUploadedFile.php';

		getUploads('background');
		getUploads('foreground');

		if (KEEP_FOLDER_CLEAN)  {  //remove all old images
			$D=opendir(IMAGE_FOLDER);
			while ($Dentry=readdir($D))  { if ($Dentry=="." or $Dentry==".."  or is_dir($Dentry))  continue;
				if (filectime(IMAGE_FOLDER.$Dentry)+LINGER*60<time())  unlink(IMAGE_FOLDER.$Dentry);  }
			closedir($D);  }

		if (is_file(IMAGE_FOLDER.$_SESSION['picName']))  {
			unlink(IMAGE_FOLDER.$_SESSION['picName']);
			$_SESSION['picName']=preg_replace("/\[([0-9]+)\]/e", 'updatePicName("$1")', $_SESSION['picName']);  }

		if (KEEP_FOLDER_CLEAN)  {  //remove all old uploads
			$D=opendir(UPLOAD_FOLDER);
			while ($Dentry=readdir($D))  { if ($Dentry=="." or $Dentry==".."
				or  UPLOAD_FOLDER.$Dentry===$_POST['background']['file']['name']
				or  ($_SESSION['foregrounds']  and  in_array(UPLOAD_FOLDER.$Dentry, $_SESSION['foregrounds'])))  continue;
				if (filectime(UPLOAD_FOLDER.$Dentry)+LINGER*60<time())  unlink(UPLOAD_FOLDER.$Dentry);  }
			closedir($D);  }

		$passtime=time();  $mpasstime=microtime(TRUE);
		$Rainbow=new RainbowBuilder;
		$Rainbow->xception=TRUE; // throw exceptions for user errors
		$Rainbow->¿showStats=TRUE;  // echo stats in HTML
//		$Rainbow->¿dumpAttributes=TRUE;  // echo the data input into the Rainbow Class

		$hw=array(
			'sizeTo'  =>$_POST['hw']['sizeTo'],
			'ratio_1' =>$_POST['hw']['ratio_1']/100,
			'width'   =>$_POST['hw']['width'],
			'overSpan'=>$_POST['hw']['overSpan'],
			'pie_slices'=>$_POST['pie'] );
		$rotate=$_POST['rotate'];  $spiral=$_POST['spiral'];
		$spiral['doso']=($spiral['doso']==='spiral');
		$spiral['factor']=$spiral['factor']/100;
//		preg_match('/^[^0-9]+/', $_POST['style'], $s);   $s=$s[0];
		switch ($_POST['style'])  {
			case 'circle': { $hw['ratio_1']=1;
				$_POST['hw']['ratio_1']='100';  break;  }
//			case 'ellipse': { $hw['sectors_1']=2;  $hw['swell']=1;
//				$_POST['hw']['sectors_1']='2';  $_POST['hw']['swell']='100';  break;  }
			case 'flower': {
				$hw['sectors_1']=$_POST['hw']['sectors_1'];
				$hw['depth']=$_POST['hw']['depth']/100;
				$hw['swell']=1-$hw['depth'];
				$_POST['hw']['swell']=100-$_POST['hw']['depth'];  break;  }
			case 'superstar': {
//			case 'star☼':
//			case 'starlet': {
				$rotate['twist']['amount']=$rotate['twist']['amount']/100;
				$rotate['twist']['depth']=$rotate['twist']['depth']/100;
				if ($rotate['twist']['extent']!=='∞')
				$rotate['twist']['extent']=$rotate['twist']['extent']/100;
				$rotate['shimmer']['amount']=$rotate['shimmer']['amount']/100;
				$rotate['shimmer']['expand']=$rotate['shimmer']['expand']/100;
				$rotate['shimmer']['depth']=$rotate['shimmer']['depth']/100;
				if ($rotate['shimmer']['extent']!=='∞')
				$rotate['shimmer']['extent']=$rotate['shimmer']['extent']/100;
				$rotate['pinwheel']=$rotate['pinwheel']/100;  }
			case 'complex':  {
				$hw['swell']=$_POST['hw']['swell']/100;  }
			case 'star': {
				$hw['depth']=$_POST['hw']['depth']/100;  }
			case 'polygon':  {
				$hw['sectors_1']=$_POST['hw']['sectors_1'];  break;  }
			case 'fountain': {
				$hw['swell']=$_POST['hw']['swell']/100;  $hw['span']=$_POST['hw']['span']/100;
				break;  }  }
		if (isset($_POST['superstyle']))  {
			$hw['ratio_2']=$_POST['hw']['ratio_2']/100;
			$hw['size_2']=$_POST['hw']['size_2']/100;
			$hw['shift_2']=$_POST['hw']['shift_2']/100;
			$hw['sectors_2']=$_POST['hw']['sectors_2'];  }

		$dim=$_POST['dimension'];  $dim['scale']=$dim['scale']/100;
		$shape=$star=NULL;
		switch ($_POST['style'])  {
			case 'line': {
				$rainbowImg=$Rainbow->gradient($dim, $_POST['background'], $_POST['foreground'], $_POST['color'], $_POST['curve'], $_POST['transp'], $hw, $rotate);
				break;  }
//			case 'star☼':
			case 'superstar': {$shape=new ComplexStar($_POST['superstar']);}
			case 'star':  {$star=TRUE;}
			case 'polygon': {if (!$shape)  $shape=new RegularPolygon($star);}
			case 'polygonic': {if (!$shape)  $shape=new Polygonic(IrregularPolygons::getSchema($_POST['irregularPolygon']));}    //  {$x=; echo"<pre>",var_dump($x),"</pre>";
			case 'mask': { if (!$shape)  {
				if ($_POST['mask']['0']['preload']=='true'  and  is_file($_SESSION['mask']))  $mask=$_SESSION['mask'];
				else  $mask=$_SESSION['mask']=getUploadedFile('mask', 0, UPLOAD_DEST, RainbowBuilder::filetypes(), TRUE);
				$shape=new RadialMask(array('name'=>$mask, 'scalable'=>($_POST['mask']['0']['scalable']=='true')));  }  }
			case 'complex':
			case 'flower': {if (!$shape)  $shape=new ComplexFlower;}
			case 'ellipse':{if (!$shape)  $shape=new Ellipse;}
			case 'circle': { if (!$shape)  $shape='circle';
				if (!isset($_POST['superstyle']))  {
					$rainbowImg=$Rainbow->radial($dim, $_POST['background'], $_POST['foreground'], $_POST['color'], $_POST['curve'], $_POST['transp'], $hw, $rotate, $spiral, $_POST['extend'], $shape);
					break;  }  }
			case 'fountain': {if (!$shape)  $shape=new Fountain;}
			case 'split':
			case 'basic': { if (!$shape)  $shape=new BasicGradient($_POST['style']==='split');
				if (isset($_POST['superstyle'])  and  in_array($_POST['superstyle'], array('hub', 'wheel', 'spokes', 'fan')))
					$rainbowImg=$Rainbow->encircle($dim, $_POST['background'], $_POST['foreground'], $_POST['color'], $_POST['curve'], $_POST['transp'], $hw, $rotate, $spiral, $_POST['extend'], $shape, $_POST['superstyle']);
				else
					$rainbowImg=$Rainbow->fountain($dim, $_POST['background'], $_POST['foreground'], $_POST['color'], $_POST['curve'], $_POST['transp'], $hw, $rotate, $spiral, $_POST['extend'], $shape, $_POST['superstyle']);
				break;  }  }
		imagealphablending($rainbowImg, FALSE);
		imagesavealpha($rainbowImg, TRUE);
		imagepng($rainbowImg, IMAGE_FOLDER.$_SESSION['picName']);
		imagedestroy($rainbowImg);
		echo
			"processing time (min:sec)= ",date('i:s', time()-$passtime)," &nbsp; (seconds)= ",microtime(TRUE)-$mpasstime,"<br />\n<br />\n",
			"<img src='",IMAGE_FOLDER,$_SESSION['picName'],"' />\n";
		}
		catch (Exception $e)  { if ($e instanceof ErrorException)
				echo '<h4>Internal Error:<br />',$e->getMessage(),'<br />on line ',$e->getLine(),' in ',$e->getFile(),"</h4>\n";
			else  echo "<h4>",htmlspecialchars($e->getMessage(), ENT_QUOTES),"</h4>\n";  }
		if (DUMP_UPLOADS)  {
			if ($_POST['background']['file']['name'])  unlink($_POST['background']['file']['name']);
			for ($i=0; $i<$foreCount; $i++)  {
				if ($_POST['foreground'][$i]['file']['name'])  unlink($_POST['foreground'][$i]['file']['name']);  }  }

	if (is_array($Rainbow->errMessages))
	foreach ($Rainbow->errMessages as $msg)  { if (is_string($msg)  and  (!is_object($e)  or  $msg!==$e->getMessage()))
		echo "<h4>",htmlspecialchars($msg, ENT_QUOTES),"</h4>\n";  }

	} // done processing new Rainbow image

	
	else  try  {
	if ($_POST['gallery']==='save'  and  (ALLOW_GALLERY & SAVETO)  and  is_file(IMAGE_FOLDER.$_SESSION['picName']))  {
		if ((ALLOW_GALLERY & PASSWORD)  and  $_POST['galleryPass']!==GALLERY_PASSWORD)
			throw New Exception('Pass Word is not correct');
		$_POST['userFileName']=preg_replace('/[\/\\\:*?<>|\x00-\x2F]/', "", $_POST['userFileName']);
		if ($_POST['userFileType']==='.png')
			rename(IMAGE_FOLDER.$_SESSION['picName'], GALLERY_FOLDER.$_POST['userFileName'].".png");
		else  {
			$DI=imagecreatefrompng(IMAGE_FOLDER.$_SESSION['picName']);
			switch($_POST['userFileType'])  {
			case '.jpg': {imagejpeg($DI, GALLERY_FOLDER.$_POST['userFileName'].".jpg");  break;}
			case '.gif': {imagegif($DI, GALLERY_FOLDER.$_POST['userFileName'].".gif");  break;}  }
			imagedestroy($DI);
			unlink(IMAGE_FOLDER.$_SESSION['picName']);  }
		unset($_SESSION['picName']);
		echo "<h3>Image saved to Gallery</h3>\n";  }  }
	catch (Exception $e)  {echo "<h4>",htmlspecialchars($e->getMessage(), ENT_QUOTES),"</h4>\n";}


Function getUploads($filefield)  { //echo "<pre>",var_dump($_POST[$filefield]),"</pre>";

	$c=count($_POST[$filefield]);
	
	for ($i=0; $i<$c; $i++)  { switch ($_POST[$filefield][$i]['preload']['flag'])  {
	case 'true': {
		if (in_array(UPLOAD_DEST.$_POST[$filefield][$i]['preload']['name'], $_SESSION['uploads'])
		and  is_file(UPLOAD_DEST.$_POST[$filefield][$i]['preload']['name']))
			$_POST[$filefield][$i]['file']['name']=UPLOAD_DEST.$_POST[$filefield][$i]['preload']['name'];
		else
		if (in_array(GALLERY_FOLDER.$_POST[$filefield][$i]['preload']['name'], getGallery()))
			$_POST[$filefield][$i]['file']['name']=GALLERY_FOLDER.$_POST[$filefield][$i]['preload']['name'];
		break;  }
	case 'recurse': { if (is_file(IMAGE_FOLDER.$_SESSION['picName']))  {
		rename(IMAGE_FOLDER.$_SESSION['picName'], UPLOAD_DEST.$_SESSION['picName']);
		addUnique($_SESSION['uploads'],
			$_POST[$filefield][$i]['file']['name']=UPLOAD_DEST.$_SESSION['picName'] );
		$_SESSION['picName']=newPicName();
		break;  }  }
	case 'false':
	default: {
		if (($upLoad=getUploadedFile($filefield, $i, UPLOAD_DEST, RainbowBuilder::filetypes(), TRUE))!==NULL)
			addUnique($_SESSION['uploads'], $_POST[$filefield][$i]['file']['name']=$upLoad);
		else  {unset($_POST[$filefield][$i]);  continue 2;}  }  }
	$_POST[$filefield][$i]['file']['scalable']=$_POST[$filefield][$i]['scalable'];  }

	$_POST[$filefield]=array_merge($_POST[$filefield]);  }


Function newPicName()  {return 'newRainbow'.(string)rand(0, 10000).'[0].png';}
Function updatePicName($i)  {return '[' . (string)(((int)$i)+1) . ']';}

Function addUnique(&$A, $d) {if (!in_array($d, $A))  $A[]=$d;}

// our internal file names for uploaded files have a folder and a session-id prefixed.
// we don't want to show that to the user.
Function username($file)  {$file=basename($file);  return substr($file, strpos($file, '.')+1);}

Function sanitize($submission) {
	if (is_array($submission))  {array_walk($submission, 'sanitize');  return $submission;}
	else  if (is_string($submission))  return htmlspecialchars($submission, ENT_QUOTES);
	else  return $submission;  }

	$_POST=sanitize($_POST);

Function getGallery ($i=NULL)  { Static $gallery;
	if (!is_array($gallery))  { $gallery=array();
		$GF=opendir(GALLERY_FOLDER);
		while ($Dentry=readdir($GF))  {
			if ($Dentry=="." or $Dentry==".." or !in_array(strrchr($Dentry, "."), RainbowBuilder::filetypes()))  continue;
			$gallery[]=GALLERY_FOLDER.$Dentry;  }
		closedir($GF);  }
	return ($i===NULL) ? $gallery : $gallery[$i];  }



try {
require_once 'plug_in_Shapes/RadialShape/ComplexStar.php';   //so we can retrieve the names of the stars

require_once 'file_path_exists.php';
if (PHP_MAJOR_VERSION>=5  and  PHP_MINOR_VERSION>=3  and  file_path_exists('plug_in_Shapes/RadialShape/Rainbow~IrregularPolygons.php'))
	include_once 'plug_in_Shapes/RadialShape/Rainbow~IrregularPolygons.php'; //the IrregularPolygon Class which manages a collection of arrays defining polygons

if ((ALLOW_GALLERY & SHOW)  and $_POST['gallery']==='view Gallery')
	echo '<h3>Gallery is shown at the bottom of this page</h3>';

?>
<form method='POST' action='<?php echo $_SERVER['PHP_SELF']; ?>' enctype='multipart/form-data'>
<?php require 'color-pickers/SoftMoon.color-pickers.php' ?>

<fieldset><legend>What style of graphic?</legend>
	<fieldset id='styler'>
		<ul>
		<li><label><input type='radio' name='style' value='line' onclick='setStyle(this.value);' <?php
		 if (!isset($_POST['style'])  or  $_POST['style']==='line')  echo 'checked="checked" '; ?>/>linear/block<span>&nbsp;—primitive &amp; dirty, but fast</span></label></li>
		<li><label><input type='radio' name='style' value='circle' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='circle')  echo 'checked="checked" '; ?>/>circle</label></li>
		<li><label><input type='radio' name='style' value='ellipse' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='ellipse')  echo 'checked="checked" '; ?>/>ellipse</label></li>
		<li><label><input type='radio' name='style' value='complex' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='complex')  echo 'checked="checked" '; ?>/>complex<span>&nbsp;—from simple ellipses to complex flowers</span></label></li>
		<li><label><input type='radio' name='style' value='flower' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='flower')  echo 'checked="checked" '; ?>/>flower<span>&nbsp;—(epicycloidic)</span></label></li>
		<li><label><input type='radio' name='style' value='superstar' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='superstar')  echo 'checked="checked" '; ?>/><select name='superstar' onmouseover='if (navigator.userAgent.match( /MSIE|Firefox/ )) this.title="YOU MUST DOUBLE CLICK and/or HOLD DOWN THE BOTTON FOR 1 SECOND to OPEN THIS PULLDOWN";'
			onclick='this.previousSibling.checked=true; this.previousSibling.onclick(); var s=this; setTimeout(function() {s.focus();}, 1);' onchange='this.previousSibling.checked=true; this.previousSibling.onclick();'>
<?php  foreach (ComplexStar::getStars() as $ss)  {
			echo "\t\t\t<option",($_POST['superstar']===$ss) ? ' selected="selected"' : "",">$ss</option>\n";  }  ?>
			</select><span>&nbsp;—complex stars that twist and shimmer</span></label></li>
		<li><label><input type='radio' name='style' value='star' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='star')  echo 'checked="checked" '; ?>/>star</label></li>
		<li><label><input type='radio' name='style' value='polygon' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='polygon')  echo 'checked="checked" '; ?>/>polygon<span>&nbsp;—all sides &amp; angles equil (regular polygon)</span></label></li>
<?php if (class_exists('IrregularPolygons')): ?>
		<li><label><input type='radio' name='style' value='polygonic' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='polygonic')  echo 'checked="checked" '; ?>/><select name='irregularPolygon' onmouseover='if (navigator.userAgent.match( /MSIE|Firefox/ )) this.title="YOU MUST DOUBLE CLICK and/or HOLD DOWN THE BOTTON FOR 1 SECOND to OPEN THIS PULLDOWN";'
		 onclick='this.previousSibling.checked=true; this.previousSibling.onclick(); var s=this; setTimeout(function() {s.focus();}, 1);' onchange='this.previousSibling.checked=true; this.previousSibling.onclick();'>
<?php foreach (IrregularPolygons::getNames() as $n)  {
			echo "\t\t\t<option",($_POST['irregularPolygon']===$n) ? ' selected="selected"' : "",">$n</option>\n";}  ?>
			</select><span>&nbsp;—custom sided and user-defined (irregular polygons)</span></label></li>
<?php endif; ?>
		<li><label><input type='radio' name='style' value='fountain' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='fountain')  echo 'checked="checked" '; ?>/>fountain</label></li>
		<li><label><input type='radio' name='style' value='basic' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='basic')  echo 'checked="checked" '; ?>/>basic-block</label></li>
		<li><label><input type='radio' name='style' value='split' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='split')  echo 'checked="checked" '; ?>/>split-block</label></li>
		<li><fieldset><label><input type='radio' name='style' value='mask' onclick='setStyle(this.value);' <?php
		 if ($_POST['style']==='mask')  echo 'checked="checked" '; ?>/>user mask<span>&nbsp;—(bright foreground on near-black background)</span></label>
		 <fieldset id='masks'><legend>mask file</legend>
				<label>¿<input type='checkbox' name='mask[0][scalable]' value='true' <?php echo
				($_POST['mask']['0']['scalable']) ? "checked='checked' " : ''; ?>/>
				scalable?<span>¿resample (resize) this image according to the master scale?</span></label>
		 <?php   //echo "<pre>",var_dump($_FILES),"</pre>";
			if ($_FILES['mask']['name'][0]['file']  or  $_POST['mask']['0']['preload']):  echo
			"<label><input type='radio' name='mask[0][preload]' value='true' checked='checked' />use ",username($_SESSION['mask']),
			"</label>\n<label for='mask[0][file]'><input type='radio' name='mask[0][preload]' value='' />new file:</label>";
			endif;
		 ?><input type='file' name='mask[0][file]' size='17' accept='image/png,image/gif,image/jpeg' /></fieldset></fieldset></li>
		</ul>
		<fieldset id='superstyle'><label><input type='checkbox' name='superstyle' value='nova' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='nova')  echo 'checked="checked" '; ?>/>nova</label>
				<label><input type='checkbox' name='superstyle' value='supernova' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='supernova')  echo 'checked="checked" '; ?>/>supernova<span>¡Warning! This is a <em>slow</em> process!</span></label>
				<label><input type='checkbox' name='superstyle' value='nebula' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='nebula')  echo 'checked="checked" '; ?>/>nebula<span>¡Warning! This is a <em>very slow</em> process!</span></label>
				<label><input type='checkbox' name='superstyle' value='quasar' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='quasar')  echo 'checked="checked" '; ?>/>quasar<span>¡Warning! This is a <em>very slow</em> process!</span></label>
				<label><input type='checkbox' name='superstyle' value='hub' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='hub')  echo 'checked="checked" '; ?>/>hub</label>
				<label><input type='checkbox' name='superstyle' value='wheel' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='wheel')  echo 'checked="checked" '; ?>/>wheel<span>¡Warning! This is a <em>slow</em> process!</span></label>
				<label><input type='checkbox' name='superstyle' value='spokes' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='spokes')  echo 'checked="checked" '; ?>/>spokes<span>¡Warning! This is a <em>very slow</em> process!</span></label>
				<label><input type='checkbox' name='superstyle' value='fan' onclick='setStyle(this.value);' <?php
		 if ($_POST['superstyle']==='fan')  echo 'checked="checked" '; ?>/>fan<span>¡Warning! This is a <em>very slow</em> process!</span></label>
				<fieldset><legend>quasar overlap</legend>
					<label><input type='radio' name='rotate[sectors_3]' value='clockwise' <?php if ($_POST['rotate']['sectors_3']!=='counter-clockwise')  echo 'checked="checked" '; ?>/>clockwise</label>
					<label><input type='radio' name='rotate[sectors_3]' value='counter-clockwise' <?php if ($_POST['rotate']['sectors_3']==='counter-clockwise')  echo 'checked="checked" '; ?>/>counter-clockwise</label>
				</fieldset></fieldset>
		<fieldset id='rotate'><legend>rotate (degrees)<span><strong>+</strong> clockwise<br /><strong>&minus;</strong> counter-clockwise</span></legend>
			<div><!-- fix Firefox - I've had to overhaul and re-write the CSS and add superfluous HTML tags because this browser and Google's Chrome DON'T work with “modern” design techniques.  -->
			<label>graphic<span>&nbsp;(x-y axes)</span><input type='text' name='rotate[graph]' size='7' maxlength='7' value='<?php echo round($_POST['rotate']['graph'], 3),'°'; ?>' onkeyup='charFilter(this, {filters:charFilter.degrees})' onblur='this.value=charFilter(this, flagFinal)+"°"' /></label>
			<label>nova<span>&nbsp;(x-y axes)</span><input type='text' name='rotate[sectors_2]' size='7' maxlength='7' value='<?php echo round($_POST['rotate']['sectors_2'], 3),'°'; ?>' onkeyup='charFilter(this, {filters:charFilter.degrees})' onblur='this.value=charFilter(this, flagFinal)+"°"' /></label>
			<label>slices<span>&nbsp;(around x-y axes)</span><input type='text' name='rotate[pie_slices]' size='7' maxlength='7' value='<?php echo round($_POST['rotate']['pie_slices'], 3),'°'; ?>' onkeyup='charFilter(this, {filters:charFilter.degrees})' onblur='this.value=charFilter(this, flagFinal)+"°"' /></label>
			<label>spiral<span>&nbsp;(around x-y axes)</span><input type='text' name='spiral[rotate]' size='7' maxlength='7' value='<?php echo round($_POST['spiral']['rotate'], 3),'°'; ?>' onkeyup='charFilter(this, {filters:charFilter.degrees})' onblur='this.value=charFilter(this, flagFinal)+"°"' /></label>
			<label>points<span>&nbsp;(around x-y axes)</span><input type='text' name='rotate[sectors_1]' size='7' maxlength='7' value='<?php echo round($_POST['rotate']['sectors_1'], 3),'°'; ?>' onkeyup='charFilter(this, {filters:charFilter.degrees})' onblur='this.value=charFilter(this, flagFinal)+"°"' /></label>
			<label>pinwheel<span>&nbsp;(percent of point)</span><input type='text' name='rotate[pinwheel]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['pinwheel']) ? round($_POST['rotate']['pinwheel'], 3) : '100'; ?>' onkeyup='charFilter(this, signedPercent)' onblur='charFilter(this, finalSignedPercent)' />%</label>
			<fieldset>
			<label>twist<span>&nbsp;(percent of point)</span><input type='text' name='rotate[twist][amount]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['twist']['amount']) ? round($_POST['rotate']['twist']['amount'], 3) : '0'; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)' />%</label>
			<label>depth<span>&nbsp;(from edge of star inward)</span><input type='text' name='rotate[twist][depth]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['twist']['depth']) ? round($_POST['rotate']['twist']['depth'], 3)  : '100'; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, {min:(-Infinity), max:100, dflt:100, filters:charFilter.limitedNumbers, flagFinal:true})' />%</label>
			<label>extent<span>&nbsp;(from center of star outward)<br />&nbsp;(click for Infinity:
				<button name='inf' type='button' onclick='infinity(this)'>∞</button> )</span><input type='text' name='rotate[twist][extent]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['twist']['extent']) ? round($_POST['rotate']['twist']['extent'], 3) : ($_POST['rotate']['twist']['extent']==='∞' ? '∞' : '100'); ?>' onkeyup='charFilter(this, infinatePercent)' onblur='charFilter(this, finalInfinatePercent)' />%</label>
			</fieldset>
			<fieldset>
			<label>shimmer<span>&nbsp;(percent of point)</span><input type='text' name='rotate[shimmer][amount]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['shimmer']['amount']) ? round($_POST['rotate']['shimmer']['amount'], 3) : '0'; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, {min:-100, max:100, dflt:"0", filters:charFilter.limitedNumbers, flagFinal:true})' />%</label>
			<label>wiggles<span>&nbsp;(number of shimmers)</span><input type='text' name='rotate[shimmer][wiggles]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['shimmer']['wiggles']) ? round($_POST['rotate']['shimmer']['wiggles'], 3) : '2'; ?>' onkeyup='charFilter(this, posInteger)' onblur='charFilter(this, finalPosInteger)' /></label>
			<label>expansion<span>&nbsp;(percent of ‘natural’)</span><input type='text' name='rotate[shimmer][expand]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['shimmer']['expand']) ? round($_POST['rotate']['shimmer']['expand'], 3) : '100'; ?>' onkeyup='charFilter(this, infinatePercent)' onblur='charFilter(this, finalInfinatePercent)' />%</label>
			<label>depth<span>&nbsp;(from edge of star inward)</span><input type='text' name='rotate[shimmer][depth]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['shimmer']['depth']) ? round($_POST['rotate']['shimmer']['depth'], 3) : '100'; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, {min:(-Infinity), max:100, dflt:100, filters:charFilter.limitedNumbers, flagFinal:true})' />%</label>
			<label>extent<span>&nbsp;(from center of star outward)<br />&nbsp;(click for Infinity:
				<button name='inf' type='button' onclick='infinity(this)'>∞</button> )</span><input type='text' name='rotate[shimmer][extent]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['rotate']['shimmer']['extent']) ? round($_POST['rotate']['shimmer']['extent'], 3) : ($_POST['rotate']['shimmer']['extent']==='∞' ? '∞' : '100'); ?>' onkeyup='charFilter(this, infinatePercent)' onblur='charFilter(this, finalInfinatePercent)' />%</label>
			</fieldset>
			</div>
		</fieldset>
		<fieldset><legend>¿ extend colorband ?</legend>
			<label><input type='radio' name='extend[doso]' value='false' <?php
			 if ($_POST['extend']['doso']!=='reflect'  and  $_POST['extend']['doso']!=='repeat')  echo 'checked="checked" '; ?>/>No</label>
			<label>reflect<input type='radio' name='extend[doso]' value='reflect' <?php
			 if ($_POST['extend']['doso']==='reflect')  echo 'checked="checked" '; ?>/></label>
			<label><input type='text' name='extend[times]' size='1' maxlength='2' value='<?php
			 echo (is_numeric($_POST['extend']['times'])) ? round($_POST['extend']['times']) : '∞'; ?>' onkeyup='charFilter(this, infinateInteger)' onblur='charFilter(this, finalInfinateInteger)' />times<span>(click for Infinity:
				<button name='inf' type='button' onclick='infinity(this)'>∞</button> )</span></label>
			<label>repeat<input type='radio' name='extend[doso]' value='repeat' <?php
			 if ($_POST['extend']['doso']==='repeat')  echo 'checked="checked" '; ?>/></label>
		</fieldset>
		<fieldset id='spiral'><legend>apply colorband</legend>
			<label><input type='checkbox' name='color[reverse]' value='true' <?php if ($_POST['color']['reverse']==='true')  echo 'checked="checked" '; ?>/>in reverse</label>
			<label><input type='radio' name='spiral[doso]' value='radial' onchange='setSpiral(this)' <?php if ($_POST['spiral']['doso']!=='spiral')  echo 'checked="checked" '; ?>/>radially</label>
			<label><input type='radio' name='spiral[doso]' value='spiral' onchange='setSpiral(this)' <?php if ($_POST['spiral']['doso']==='spiral')  echo 'checked="checked" '; ?>/>in spiral:</label>
			<label>sectors<input type='text' name='spiral[sectors]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['spiral']['sectors']) ? round($_POST['spiral']['sectors'], 3) : 1; ?>' onkeyup='charFilter(this, posInteger)' onblur='charFilter(this, finalPosInteger)' /></label>
			<label>twist rate<span>&nbsp;(percent of sector)</span><input type='text' name='spiral[factor]' size='4' maxlength='7' value='<?php echo is_numeric($_POST['spiral']['factor']) ? round($_POST['spiral']['factor'], 3) : 100; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<label><input type='radio' name='spiral[twist]' value='clockwise' <?php if ($_POST['spiral']['twist']!=='counter-clockwise')  echo 'checked="checked" '; ?>/>clockwise</label>
			<label><input type='radio' name='spiral[twist]' value='counter-clockwise' <?php if ($_POST['spiral']['twist']==='counter-clockwise')  echo 'checked="checked" '; ?>/>counter-clockwise</label>
			<label>¿<input type='checkbox' name='spiral[squish]' value='true' <?php if ($_POST['spiral']['squish']=='true') echo " checked='checked'"; ?> />squish to h/w ratio?</label>
		</fieldset>
		<fieldset id='hw'><legend>height/width</legend>
			<label><input type='radio' name='hw[sizeTo]' value='shape' <?php if ($_POST['hw']['sizeTo']!='radius') echo 'checked="checked" '; ?>/>size to shape</label>
			<label><input type='radio' name='hw[sizeTo]' value='radius' <?php if ($_POST['hw']['sizeTo']=='radius') echo 'checked="checked" '; ?>title='best for (super)novas, nebulae, quasars' />size to radius</label>
			<label>ratio<span>of graphic element(s)</span><input type='text' name='hw[ratio_1]' size='4' maxlength='7' value='<?php
				echo is_numeric($_POST['hw']['ratio_1']) ?  round($_POST['hw']['ratio_1'], 3) : "100"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<label>swell<input type='text' name='hw[swell]' size='4' maxlength='7' value='<?php
				echo is_numeric($_POST['hw']['swell']) ?  round($_POST['hw']['swell'], 3) : "100"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<label>petals<input type='text' name='hw[sectors_1]' size='4' maxlength='4' value='<?php
				echo is_numeric($_POST['hw']['sectors_1']) ?  round($_POST['hw']['sectors_1']) : "7"; ?>' onkeyup='charFilter(this, posInteger)' onblur='charFilter(this, {min:2, max:Infinity, flagFinal:true, filters:charFilter.positiveIntegers})' /></label>
			<label>depth<input type='text' name='hw[depth]' size='4' maxlength='7' value='<?php
				echo is_numeric($_POST['hw']['depth']) ?  round($_POST['hw']['depth'], 3) : "61.8"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<label>span<input type='text' name='hw[span]' size='4' maxlength='7' value='<?php
				echo is_numeric($_POST['hw']['span']) ?  round($_POST['hw']['span'], 3) : "100"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<fieldset><legend>of nova</legend>
				<label>ratio<input type='text' name='hw[ratio_2]' size='4' maxlength='7' value='<?php
					echo is_numeric($_POST['hw']['ratio_2']) ?  round($_POST['hw']['ratio_2'], 3) : "100"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
				<label>size<span>of graphic elements</span><input type='text' name='hw[size_2]' size='4' maxlength='7' value='<?php
					echo is_numeric($_POST['hw']['size_2']) ?  round($_POST['hw']['size_2']) : "50"; ?>' onkeyup='charFilter(this, percent)' onblur='charFilter(this, {min:1, max:Infinity, dflt:50, filters:positives, flagFinal:true})' />%</label>
				<label>shift<span>graphic elements in/out</span><input type='text' name='hw[shift_2]' size='4' maxlength='7' value='<?php
					echo is_numeric($_POST['hw']['shift_2']) ?  round($_POST['hw']['shift_2']) : "0"; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, {min:-98, max:Infinity, dflt:0, filters:charFilter.limitedNumbers, flagFinal:true})' />%</label>
				<label>sectors<input type='text' name='hw[sectors_2]' size='4' maxlength='4' value='<?php
					echo is_numeric($_POST['hw']['sectors_2']) ?  round($_POST['hw']['sectors_2']) : "7"; ?>' onkeyup='charFilter(this, posInteger)' onblur='charFilter(this, {min:2, max:Infinity, flagFinal:true, filters:charFilter.positiveIntegers})' /></label>
			</fieldset>
		</fieldset>
		<fieldset id='pie'><legend>pie slices:&nbsp; by # or degrees<span>calculated from 3:00, counter-clockwise<br />(¡slices may also all be rotated!)</span></legend>
			<label>¿<input type='checkbox' name='pie[squish]' value='true' <?php if ($_POST['pie']['squish']=='true') echo " checked='checked'"; ?> />squish to h/w ratio?</label>
			<table>
			<tr><th>↓&lt;</th><th>slice #</th><th>of total</th></tr>
			<tr><th></th><th>to° ←</th><th>← from°</th></tr>
			<?php $c=(is_array($_POST['pie']) ? count($_POST['pie']) : 0);  for ($i=0; $i<=$c; $i++)  {
				//  the Function “is_number” will only be loaded when the Rainbow Class is loaded...
				if ($i==$c  or  is_number($_POST['pie'][$i]['to'])  and  is_number($_POST['pie'][$i]['from'])):  ?>
			<tr><td><input type='checkbox' name='pie[<?php echo $i; ?>][sliceFlag]' value='true'<?php if ($_POST['pie'][$i]['sliceFlag']=='true') echo " checked='checked'"; ?> onclick='setPieType(this);' title='by slice (numbered) of (total)' /></td>
			<td><input type='text' <?php echo "name='pie[$i][to]' value='",$_POST['pie'][$i]['to'],"'"; ?> size='7' maxlength='7' onfocus='tabbedOut=false' onkeydown='catchTab(event)' onkeyup='setPieType(this)' onblur='setPieType(this, flagFinal);  pieSlice.popNewField(this.parentNode.parentNode)' /></td>
			<td><input type='text' <?php echo "name='pie[$i][from]' value='",$_POST['pie'][$i]['from'],"'"; ?> size='7' maxlength='7' onfocus='tabbedOut=false' onkeydown='catchTab(event)' onkeyup='setPieType(this)' onblur='setPieType(this, flagFinal);  pieSlice.popNewField(this.parentNode.parentNode);' /></td>
			<td class='formOptions'>
				<span onclick='pieSlice.popNewField(this.parentNode.parentNode, {doso:"delete"})'>←delete this slice</span>
			</td>
			</tr>
			<?php endif;  }  ?>
			</table>
		</fieldset>

		<!-- <fieldset style='display: none'><legend>radial point</legend>
			<label>x-offset<input type='text' name='xOff' size='4' maxlength='4' value='<?php echo $_POST['xOff']; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)' /></label>
			<label>y-offset<input type='text' name='yOff' size='4' maxlength='4' value='<?php echo $_POST['yOff']; ?>' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)' /></label>
		</fieldset> -->
	</fieldset>
	<fieldset id='background'><legend>background</legend>
		<fieldset>
			<label>color<input type='text' name='background[color]' value='<?php echo $_POST['background']['color']; ?>'
				size='20' maxlength='20' onkeydown='catchTabPopDown(event, this);' onkeyup='ColorPicker.colorSwatch(this)'
				onfocus='ColorPicker.showTable(true, this)' onblur='ColorPicker.showTable(false, this); ColorPicker.colorSwatch(this);'
			/><span class='colorSwatch'> </span></label>
			<label>¿<input type='checkbox' name='background[transp][flag]' value='true'<?php
				echo ($_POST['background']['transp']['flag']==='true') ? ' checked="checked"' : ""; ?>
				onclick='setTransp(this);' />?transparency<span><input
				type='text' name='background[transp][percent]' value='<?php echo $_POST['background']['transp']['percent']; ?>'
				size='7' maxlength='7' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalPercent0)'
			/>%</span></label>
			<label>¿<input type='checkbox' name='background[transp][apply][flag]' value='true'<?php
				echo ($_POST['background']['transp']['apply']['flag']==='true') ? ' checked="checked"' : ""; ?>
				onclick='setTransp(this);' />?apply final transparency<span><input
				type='text' name='background[transp][apply][percent]' value='<?php echo $_POST['background']['transp']['apply']['percent']; ?>'
				size='7' maxlength='7' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalPercent0)'
			/>%</span></label>
		</fieldset>
		<div>
<?php
Function showUploadFields($z, $tab)  { global $Rainbow;
	$cu=count($_SESSION['uploads']);
	$cg=(ALLOW_GALLERY & ACCESS) ? count(getGallery()) : 0;
	$c=((DUMP_UPLOADS) ? 0 : count($_POST[$z]));
	for ($i=0; $i<=$c; $i++)  {
	echo
		"$tab<fieldset class='$z'><legend>$z image</legend>\n"; ?>
	<div class='formOptions'>
		<span onclick='userFile.popNewField(this.parentNode.parentNode, {doso:"insert"})'>↑insert new image↑</span>
		<span onclick='userFile.popNewField(this.parentNode.parentNode, {doso:"delete"})'>←delete this image</span>
	</div><?php  echo
		"$tab<label>¿<input type='checkbox' name='{$z}[$i][fitto]' value='true' ",
			($_POST[$z][$i]['fitto']) ? "checked='checked' " : '', "/>",
		"fit to this?<span>¿include this image when figuring overall background size?</span></label>\n",
		"$tab<label>¿<input type='checkbox' name='{$z}[$i][scalable]' value='true' ",
			($_POST[$z][$i]['scalable']) ? "checked='checked' " : '', "/>",
		"scalable?<span>¿resample (resize) this image according to the master scale?</span></label>\n";
	if ($cu+$cg>0)  { echo
		"$tab <label><input type='radio' name='{$z}[$i][preload][flag]' value='true' ", ($i<$c) ? "checked='checked'" : "",
		" onchange='if (this.checked) userFile.popNewField(this.parentNode.parentNode)' />\n",
		"$tab  use <select name='{$z}[$i][preload][name]'>\n";
		for ($j=0; $j<$cu; $j++)  { echo
			"$tab   <option", ($_POST[$z][$i]['file']['name']===$_SESSION['uploads'][$j]) ? " selected='selected'" : "",
			">",username($_SESSION['uploads'][$j]),"</option>\n";  }
		for ($j=0; $j<$cg; $j++)  { echo
			"$tab   <option", ($_POST[$z][$i]['file']['name']===getGallery($j)) ? " selected='selected'" : "",
			">",basename(getGallery($j)),"</option>\n";  }
		echo "$tab </select></label>\n";   }
	if (is_object($Rainbow) and $Rainbow->successful)  echo
		"$tab <label><input type='radio' name='{$z}[$i][preload][flag]' value='recurse' onchange='if (this.checked) userFile.popNewField(this.parentNode.parentNode)' />\n",
		"$tab   use the current graphic (page top)</label>\n";
	if ($cu+$cg>0  or  is_object($Rainbow) and $Rainbow->successful)  echo
		"$tab <label><input type='radio' name='{$z}[$i][preload][flag]' value='false'",
		($i==$c  or  $_POST[$z][$i]['file']['name']=="") ? " checked='checked'" : "",
		"onchange='if (this.checked) userFile.popNewField(this.parentNode.parentNode)' />\n";
	else  echo "$tab <label>\n";
	echo
		"$tab   upload new $z file:\n",
		"$tab <input type='file' name='{$z}[$i][file]' size='17' accept='image/png,image/gif,image/jpeg'\n",
		"$tab  onkeydown='catchTab(event)' onfocus='tabbedOut=false'\n",
//		"$tab  onblur='userFile.popNewField(this.parentNode.parentNode, fileOpts)'\n",
		"$tab  onchange='userFile.popNewField(this.parentNode.parentNode)'\n",
		"$tab /></label>\n",
		"$tab <fieldset>\n",
		"$tab  <select name='{$z}[$i][position]' onchange='setPosition(this, true);'>\n",
		"$tab   <option", ($_POST[$z][$i]['position']==NULL  or  $_POST[$z][0]['position']==="center") ? ' selected="selected"' : "", ">center</option>\n",
		"$tab   <option", ($_POST[$z][$i]['position']==="tiled") ? ' selected="selected"' : "", ">tiled</option>\n",
		"$tab   <option", ($_POST[$z][$i]['position']==="x,y") ? ' selected="selected"' : "", ">x,y</option>\n",
		"$tab  </select>\n",
		"$tab  <label><input type='text' name='{$z}[$i][xy]' value='",
			(is_array($_POST[$z][$i]['xy'])) ? implode(",", $_POST[$z][$i]['xy']) : $_POST[$z][$i]['xy'],
			"' size='8' maxlength='8'\n",
		"$tab   onkeydown='catchTab(event)' onkeyup='charFilter(this, coordinate)' onfocus='tabbedOut=false'\n",
		"$tab   onblur='charFilter(this, finalCoordinate);' /><span>(x, y) position of upper-left corner</span></label>\n",
		"$tab  <label><input type='text' name='{$z}[$i][wh]' value='",
			(is_array($_POST[$z][$i]['wh'])) ? implode(",", $_POST[$z][$i]['wh']) : $_POST[$z][$i]['wh'],
			"' size='8' maxlength='8'\n",
		"$tab   onkeydown='catchTab(event)' onkeyup='charFilter(this, dimensions_2D)' onfocus='tabbedOut=false'\n",
		"$tab   onblur='charFilter(this, finalDimensions_2D);' /><span>(width, height) count tiles</span></label>\n",
		"$tab </fieldset>\n",
		"$tab <fieldset><legend>blend file transparencies?</legend>\n",
		"$tab  <label><input type='radio' name='{$z}[$i][alphablend]' value='into background'", ($_POST[$z][$i]['alphablend']!=="retain transp") ? ' checked="checked"' : "", "/>\n",
		"$tab   into", ($z=='foreground') ? ' rainbow &amp;' : "", " background</label>\n",
		"$tab  <label><input type='radio' name='{$z}[$i][alphablend]' value='retain transp'", ($_POST[$z][$i]['alphablend']==="retain transp") ? ' checked="checked"' : "", "/>\n",
		"$tab   retain transparency &mdash; replace underlying pixels</label>\n",
		"$tab </fieldset>\n",
		"$tab <label>Master Opacity: <input type='text' name='{$z}[$i][opacity]' value='",
		($_POST[$z][$i]['opacity']) ? $_POST[$z][$i]['opacity'] : '100', "'\n",
		"$tab  size='4' maxlength='7' onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalPercent)' />%</label>\n",
		"$tab</fieldset>\n";
	if ($_POST[$z][$i]['file']['name']=="")  $i=$c;  }  }

showUploadFields("background", "\t\t\t");
?>
		</div>
	</fieldset>
	<div>
<?php showUploadFields("foreground", "\t\t"); ?>
	</div>
	<fieldset id='dimensions'><legend>overall image dimensions</legend>
		<label>¿<input type='checkbox' name='dimension[fitto]' value='true' <?php
			if ($_POST['dimension']['fitto']) echo "checked='checked' "; ?>/>
		 fit to this?<span>¿include your created graphic when figuring overall background size?</span></label>
		<div>
			<select name='dimension[type]' onchange='setDimensions(this)'>
				<option<?php if ($_POST['dimension']['type']==NULL  or  $_POST['dimension']['type']==="auto to rainbow")  echo ' selected="selected"'; ?>>auto to rainbow</option>
				<option<?php if ($_POST['dimension']['type']==="with margin")  echo ' selected="selected"'; ?>>with margin</option>
				<option<?php if ($_POST['dimension']['type']==="absolute")  echo ' selected="selected"'; ?>>absolute</option>
				<option<?php if ($_POST['dimension']['type']==="fit to select images")  echo ' selected="selected"'; ?>>fit to select images</option>
			</select>
			<label>Master Scale: <input type='text' name='dimension[scale]' value='<?php echo
			 (is_numeric($_POST['dimension']['scale'])) ? $_POST['dimension']['scale'] : '100'; ?>' size='4' maxlength='7'
				onkeyup='charFilter(this, percent)' onblur='charFilter(this, finalUnlimitedPercent)' />%</label>
			<label>¿scale margin <input type='checkbox' name='dimension[¿scale_margin]' value='true' <?php
				if ($_POST['dimension']['scale_margin'])  echo "checked='checked '"; ?>/>?</label>
		</div>
		<div>
			<fieldset><legend>margin (pixels)<span>┼ ☼</span></legend>
				<fieldset><div><input type='radio' name='dimension[margin][origin][left]' value='center' title='from graphic center' <?php if ($_POST['dimension']['margin']['origin']['left']==='center')  echo "checked='checked '";
				 ?>/><input type='radio' name='dimension[margin][origin][left]' value='edge' title='from graphic edge' <?php if ($_POST['dimension']['margin']['origin']['left']!=='center')  echo "checked='checked '";
				 ?>/></div><input type='text' name='dimension[margin][left]' value="<?php echo round($_POST['dimension']['margin']['left']); ?>" size='3' maxlength='6' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)'
				 />left <label>→<input type='checkbox' name='dimension[margin][left]' title='auto center' value='center' <?php if ($_POST['dimension']['margin']['left']=='center') echo 'checked="checked" '; ?>onclick='autocenter(this);' />←</label></fieldset>
				<fieldset><div><input type='radio' name='dimension[margin][origin][top]' value='center' title='from graphic center' <?php if ($_POST['dimension']['margin']['origin']['top']==='center')  echo "checked='checked '";
				 ?>/><input type='radio' name='dimension[margin][origin][top]' value='edge' title='from graphic edge' <?php if ($_POST['dimension']['margin']['origin']['top']!=='center')  echo "checked='checked '";
				 ?>/></div><input type='text' name='dimension[margin][top]' value="<?php echo round($_POST['dimension']['margin']['top']); ?>" size='3' maxlength='6' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)'
				 />top <label>↓<input type='checkbox' name='dimension[margin][top]' title='auto center' value='center' <?php if ($_POST['dimension']['margin']['top']=='center') echo 'checked="checked" '; ?>onclick='autocenter(this);' />↑</label></fieldset>
				<fieldset><div><input type='radio' name='dimension[margin][origin][right]' value='center' title='from graphic center' <?php if ($_POST['dimension']['margin']['origin']['right']==='center')  echo "checked='checked '";
				 ?>/><input type='radio' name='dimension[margin][origin][right]' value='edge' title='from graphic edge' <?php if ($_POST['dimension']['margin']['origin']['right']!=='center')  echo "checked='checked '";
				 ?>/></div><input type='text' name='dimension[margin][right]' value="<?php echo round($_POST['dimension']['margin']['right']); ?>" size='3' maxlength='6' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)' />right</fieldset>
				<fieldset><div><input type='radio' name='dimension[margin][origin][bottom]' value='center' title='from graphic center' <?php if ($_POST['dimension']['margin']['origin']['bottom']==='center')  echo "checked='checked '";
				 ?>/><input type='radio' name='dimension[margin][origin][bottom]' value='edge' title='from graphic edge' <?php if ($_POST['dimension']['margin']['origin']['bottom']!=='center')  echo "checked='checked '";
				 ?>/></div><input type='text' name='dimension[margin][bottom]' value="<?php echo round($_POST['dimension']['margin']['bottom']); ?>" size='3' maxlength='6' onkeyup='charFilter(this)' onblur='charFilter(this, flagFinal)' />bottom</fieldset>
			</fieldset>
			<label>width, height <input type='text' name='dimension[xy]' value="<?php echo
				(is_array($_POST['dimension']['xy'])) ? implode(",", $_POST['dimension']['xy']) : $_POST['dimension']['xy'];
				?>" size='8' maxlength='8' onkeyup='charFilter(this, dimensions_2D)' onblur='charFilter(this, finalDimensions_2D)' /> pixels</label>
		</div>
	</fieldset>
</fieldset>
<p>When all active color fields are filled,<br />
&nbsp; • press the TAB key&nbsp; or &nbsp;• click on this page outside of the color input-boxes<br />
to generate another color band set.<br />
Previously filled color bands that are cleared will be removed.</p>
<div>
<?php
	$cnt=(is_array($_POST['color'])) ?  count($_POST['color'])  :  2;  $htm='start';  $index=(-1);
	for ($i=0; $i<=$cnt; $i++, $htm=(($i<$cnt) ? 'next' : 'end'))  {
		if ($index>=0  and  $i<$cnt  and  $_POST['color'][$i]=="")  continue;  else  $index++; ?>
<fieldset class='colorNode'>
	<div class='formOptions'>
		<span onclick='colorband.popNewField(getColorNode(this), {doso:"insert"})'>↑insert new color↑</span>
		<span onclick='colorband.popNewField(getColorNode(this), {doso:"delete"})'>←delete this color</span>
	</div>
<?php      //  class='",($index>0) ? "hiddenWhenFirst" : "hideBecauseFirst","'
		echo"<fieldset class='hiddenWhenFirst'><legend>color gradient</legend>\n",
				"<label>curve<select name='curve[type][$index]' onchange='setCurve(this)'>\n",
				" <option",
				 (!isset($_POST['curve'])  or  $_POST['curve']['type'][$i]==='none') ? ' selected="selected"' : "",
				">none</option>\n",
				" <option", ($_POST['curve']['type'][$i]==='to start') ? ' selected="selected"' : "",
				">to start</option>\n",
				" <option", ($_POST['curve']['type'][$i]==='to center') ? ' selected="selected"' : "",
				">to center</option>\n",
				" <option", ($_POST['curve']['type'][$i]==='to end') ? ' selected="selected"' : "",
				">to end</option>\n",
				"</select></label>\n",
				"<label>curve index<input type='text' name='curve[index][$index]' value='",
					($_POST['curve']['index'][$i]) ? $_POST['curve']['index'][$i] : "1.000", "' size='5' maxlength='5' onkeydown='catchTab(event)' onkeyup='charFilter(this, indexValue)' onfocus='tabbedOut=false' onblur='charFilter(this, finalIndexValue);  colorband.popNewField(getColorNode(this))' /></label>\n",
				"</fieldset>\n\n",

				"<fieldset class='hiddenWhenFirst'><legend>transparency gradient</legend>\n",
				"<label>¿<input type='checkbox' name='transp[flag][$index]' value='true' onchange='setTransp(this)'",
				 ($_POST['transp']['flag'][$i]==='true') ? ' checked="checked"' : "",
				"/>transparency?</label>\n";
			foreach (array('blend', 'pixel') as $t)  {  echo
				"<fieldset class='transp_curve'><legend>$t</legend>\n",
				"<label>curve<select name='transp[$t][curve][type][$index]' onchange='setCurve(this)'>\n",
				" <option",
				 (!isset($_POST['transp'][$t]['curve']['type'][$i])  or  $_POST['transp'][$t]['curve']['type'][$i]==='none') ? ' selected="selected"' : "",
				">none</option>\n",
				" <option", ($_POST['transp'][$t]['curve']['type'][$i]==='to start') ? ' selected="selected"' : "",
				">to start</option>\n",
				" <option", ($_POST['transp'][$t]['curve']['type'][$i]==='to center') ? ' selected="selected"' : "",
				">to center</option>\n",
				" <option", ($_POST['transp'][$t]['curve']['type'][$i]==='to end') ? ' selected="selected"' : "",
				">to end</option>\n",
				"</select></label>\n",
				"<label>curve index<input type='text' name='transp[$t][curve][index][$index]' value='",
					($_POST['transp'][$t]['curve']['index'][$i]) ? $_POST['transp'][$t]['curve']['index'][$i] : "1.000", "' size='5' maxlength='5' onkeydown='catchTab(event)' onkeyup='charFilter(this, indexValue)' onfocus='tabbedOut=false' onblur='charFilter(this, finalIndexValue);  colorband.popNewField(getColorNode(this))' /></label>\n",
				"</fieldset>\n";  }
			echo
				"<fieldset class='transp_apply'>\n",
				"<label onmouseover=\"showTutor(this, 'transpTutor')\" onmouseout=\"showTutor(false)\"><input type='radio' name='transp[alphablend][$index]' value='into background' onchange='setTransp(this, this.value)' ",
				 (!isset($_POST['transp']['alphablend'][$i])  or  $_POST['transp']['alphablend'][$i]==='into background') ? ' checked="checked"' : "",
				"/>blend into background</label>\n",
				"<label onmouseover=\"showTutor(this, 'transpTutor')\" onmouseout=\"showTutor(false)\"><input type='radio' name='transp[alphablend][$index]' value='replace background' onchange='setTransp(this, this.value)' ",
				 ($_POST['transp']['alphablend'][$i]==='replace background') ? ' checked="checked"' : "",
				"/>displace background &mdash; apply pixel transparency</label>\n",
				"<label onmouseover=\"showTutor(this, 'transpTutor')\" onmouseout=\"showTutor(false)\"><input type='radio' name='transp[alphablend][$index]' value='blend & apply' onchange='setTransp(this, this.value)' ",
				 ($_POST['transp']['alphablend'][$i]==='blend & apply') ? ' checked="checked"' : "",
				"/>blend into background &amp; apply pixel transparency</label>\n",
				"</fieldset>\n</fieldset>\n\n",
				"<label class='hiddenWhenFirst'>over <input type='text' name='hw[overSpan][$index]' value='{$_POST['hw']['overSpan'][$i]}' size='3' maxlength='3' onkeydown='catchTab(event)' onkeyup='charFilter(this, posInteger)' onfocus='tabbedOut=false' onblur='charFilter(this, finalSpan);  colorband.popNewField(getColorNode(this))' /> pixels to:</label>\n",

				"<div class='colorSelect'>\n",
				"<label>$htm color<input type='text' name='color[$index]' value='{$_POST['color'][$i]}' size='20' maxlength='20' onkeydown='catchTabPopDown(event, this)' onkeyup='ColorPicker.colorSwatch(this)' onfocus='tabbedOut=false; ColorPicker.showTable(true, this);' onblur='ColorPicker.colorSwatch(this); ColorPicker.showTable(false, this); colorband.popNewField(getColorNode(this));' /><span class='colorSwatch'> </span></label>\n",
				"<label>$htm blend transparency<input type='text' name='transp[blend][percent][$index]' value='{$_POST['transp']['blend']['percent'][$i]}' size='3' maxlength='6' onkeydown='catchTab(event)' onkeyup='charFilter(this, percent)' onfocus='tabbedOut=false' onblur='charFilter(this, finalPercent0);  colorband.popNewField(getColorNode(this))' />%</label>\n",
				"<label>$htm pixel transparency<input type='text' name='transp[pixel][percent][$index]' value='{$_POST['transp']['pixel']['percent'][$i]}' size='3' maxlength='6' onkeydown='catchTab(event)' onkeyup='charFilter(this, percent)' onfocus='tabbedOut=false' onblur='charFilter(this, finalPercent0);  colorband.popNewField(getColorNode(this))' />%</label>\n",
				"</div>\n",
				"<label>$htm width<input type='text' name='hw[width][$index]' value='{$_POST['hw']['width'][$i]}' size='3' maxlength='3' onkeydown='catchTab(event)' onkeyup='charFilter(this, posInteger)' onfocus='tabbedOut=false' onblur='charFilter(this, finalWidth);  colorband.popNewField(getColorNode(this))' /></label>\n",
				"</fieldset>\n\n";  }

	if (CHECK_PASSWORD)  $pw=$Password->generate(IMAGE_FOLDER.'PWs/', PW_DB, FONTS_FOLDER, IMAGE_FOLDER.'PWs/');

?>
</div>
<?php if (CHECK_PASSWORD and is_string($pw['url'])): ?>
<label class='password'><input type='text' name='password' value="" />Enter the password:
<img src='<?php echo $pw['url']; ?>' alt='' /></label>
<?php endif; ?>
<input class='submit' type='submit' name='show' value='<?php echo ($_POST['show']) ? 'update' : 'show'; ?> Rainbow' />
<?php if (is_object($Rainbow) and $Rainbow->successful  and  (ALLOW_GALLERY & SAVETO)): ?>
<button class='submit' name='gallery' onclick='showGalleryForm(); return false;'>add to Gallery<span>image does not update</span></button>
<div id='fileinfo'>
	<label>filename:<input type='text' name='userFileName' size='27' maxlength='62'
	 onkeydown='var e=(event || window.event);  return !(e.keyCode==13);'
	 onkeyup='charFilter(this, {filters:charFilter.fileName})' onblur='charFilter(this, {filters:charFilter.fileName})' /></label>
	<select name='userFileType' title='file type'>
		<option selected='selected'>.png</option>
		<option>.jpg</option>
		<option>.gif</option>
	</select>
	<p>Note if you save your image in a format other than .png, any embedded transparencies will be lost.</p>
	<label>Commit <input type='submit' name='gallery' value='save' onclick='return checkFilename()' /> to Gallery
		<span>¡image does not update!</span></label>
</div>
<?php endif; ?>
<?php if ((ALLOW_GALLERY & SHOW)  and $_POST['gallery']!=='view Gallery'): ?>
<input class='submit' type='submit' name='gallery' value='view Gallery' />
<?php endif; ?>
</form>
<?php if ((ALLOW_GALLERY & SHOW)  and $_POST['gallery']==='view Gallery'): ?>
<div id='gallery'>
	<h2>Image Gallery</h2>
<?php foreach (getGallery() as $gal)  { $bn=basename($gal);
	echo "\t<img src='$gal' alt='$bn' />\n\t<p>$bn</p>\n<hr />\n";  } ?>
</div>
<?php endif;
} catch (ErrorException $e)  {echo '<h4>Internal Error:<br />',$e->getMessage(),'<br />on line ',$e->getLine(),' in ',$e->getFile(),'</h4>';}
?>
</body>
</html>