Location: PHPKode > scripts > Particle Gallery > baseeditor.php
<?php
require("includes/global.php");

// functions go here
function base_newtemplate($shortie){
	global $db, $dbprefix;
	
	// standard validation
	if ($shortie == ""){ return "You did not enter a name for the template"; }
	
	// and run the insert
	$sql  = "INSERT INTO " . $dbprefix . "skinbase (shortie) VALUES (";
	$sql .= "'" . dbSecure($shortie) . "')";
	$db->execute($sql);
	
	// finally return
	return "Template created successfully";
}

function base_edittemplate($fileid, $shortie, $code){
	global $db, $dbprefix;
	
	// standard validation
	$fileid = intval($fileid);
	if ($shortie == ""){ return "No template name entered"; }
	
	// validate existance of template
	$sql = "SELECT * FROM " . $dbprefix . "skinbase WHERE fileid = " . dbSecure($fileid);
	$rec = $db->execute($sql);
	if ($rec->rows < 1){ return "Unable to locate the template"; }
	
	// update the template
	$sql  = "UPDATE " . $dbprefix . "skinbase SET shortie = '" . dbSecure($shortie) . "', ";
	$sql .= "code = '" . dbSecure($code) . "' WHERE fileid = " . dbSecure($fileid);
	$db->execute($sql);
	
	// finally return
	return "Template edited successfully";
}

function base_deletetemplate($fileid){
	global $db, $dbprefix;
	
	// standard validation
	$fileid = intval($fileid);
	
	// validate the template
	$sql = "SELECT * FROM " . $dbprefix . "skinbase WHERE fileid = " . dbSecure($fileid);
	$rec = $db->execute($sql);
	if ($rec->rows < 1){ return "The template could not be found"; }
	
	// and delete the template
	$sql = "DELETE FROM " . $dbprefix . "skinbase WHERE fileid = " . dbSecure($fileid);
	$db->execute($sql);
	
	// and return successful
	return "Template deleted successfully";
}

// check for actions
if ($_POST["do"] == "newtemplate"){
	$errormsg = base_newtemplate($_POST["new"]);
} elseif ($_POST["do"] == "Delete"){
	$errormsg = base_deletetemplate($_POST["fileid"]);
} elseif ($_POST["act"] == "Save File"){
	$errormsg = base_edittemplate($_POST["fileid"], $_POST["title"], $_POST["code"]);
} elseif ($_POST["act"] == "Cancel Edit"){
	redirect("baseeditor.php");
}

// work out which page it is
if ($_REQUEST["do"] == "Edit File"){
	$pagesect = 1;
	
	$fileid = intval($_REQUEST["fileid"]);
	$sql = "SELECT * FROM " . $dbprefix . "skinbase WHERE fileid = " . dbSecure($fileid);
	$fil = $db->execute($sql);
	if ($fil->rows < 1){ die("Unable to locate skin file"); }
	
} else {
	// work out which skin
	if ($rec->fields["visible"] == 1){
		$c1 = ' selected="selected"';
		$c2 = '';
	} else {
		$c1 = '';
		$c2 = ' selected="selected"';
	}
	
}

// get list of templates
$sql = "SELECT * FROM " . $dbprefix . "skinbase ORDER BY shortie ASC";
$tem = $db->execute($sql);

// set up variables
$core = "baseeditor.php?x=y";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><?=$config["sitename"]?> Base Template Editor</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<link rel="stylesheet" type="text/css" href="shared/popup.css" />
<script language="JavaScript" type="text/javascript" src="shared/functions.js"></script>
</head>
<body>
<div class="container">
	<div class="header">
		<div style="float: right;"><a href="javascript:null();">X</a></div>
		Base Template Editor
	</div>
	
	<div class="main">
		<?php if ($errormsg <> ""){ echo($errormsg . "<hr />"); } ?>
		
		<?php if ($pagesect == 1){ // editing a template ?>
		
		<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr>
			<td><i>Template: <?=$fil->fields["shortie"]?></i></td>
			<td style="text-align: right;">
				<form action="baseeditor.php" method="get" id="fi" name="fi">
					Change: 
					<select id="fileid" name="fileid" onChange="skinfilejump(<?=$skinid?>,document.forms.fi.fileid.options[selectedIndex].value);">
						<option value="">Select...</option>
						<?php if ($tem->rows > 0){ do { ?>
						<option value="<?=$tem->fields["fileid"]?>"><?=$tem->fields["shortie"]?></option>
						<?php } while ($tem->loop()); } ?>
					</select>
					<input type="hidden" id="skinid" name="skinid" value="<?=$skinid?>" />
					<input type="hidden" id="do" name="do" value="Edit File" />
					<input type="submit" value="GO" />
				</form>
			</td>
		</tr></table>
		<hr />
		
		<form action="<?=$core?>&do=Edit File" method="post">
			Title: <input type="text" size="30" id="title" name="title" value="<?=$fil->fields["shortie"]?>" /><br /><br />
			
			Template Code:<br />
			<textarea cols="60" rows="15" id="code" name="code"><?=htmlspecialchars($fil->fields["code"])?></textarea><br /><br />
			
			<input type="hidden" id="fileid" name="fileid" value="<?=$fil->fields["fileid"]?>" />
			<input type="hidden" id="do" name="do" value="Edit File" />
			<input type="submit" id="act" name="act" value="Save File" />
			<input type="submit" id="act" name="act" value="Cancel Edit" /><br />
			
			You can use cancel to return to the skinset overview
		</form>
		
		<?php } else { // not editing a templage ?>
		<form action="<?=$core?>" method="post">
			<strong>Edit Templates</strong><br />
			<select id="fileid" name="fileid">
				<?php do { ?>
					<option value="<?=$tem->fields["fileid"]?>"><?=$tem->fields["shortie"]?></option>
				<?php } while ($tem->loop()); ?>
			</select>
			<input type="submit" id="do" name="do" value="Edit File" />
			<input type="submit" id="do" name="do" value="Delete" />
		</form><br />
		
		<form action="<?=$core?>" method="post">
			<input type="text" size="30" maxlength="50" id="new" name="new" />
			<input type="hidden" id="do" name="do" value="newtemplate" />
			<input type="submit" value="Create New" />
		</form><br />
		
		<?php } // end pagesect check ?>
		
	</div>
	
	<div class="footer">
		&copy; Particle Soft
	</div>
</div>
</body>
</html>
Return current item: Particle Gallery