Location: PHPKode > projects > Anantasoft Gazelle CMS > admin/settemplate.php
<?php
$output = "";
if (!empty($_POST) && !isset($_GET["customizetemplate"])) {
	$output = include("sql/update.php");
}
if (!empty($_GET) && isset($_GET["customizetemplate"]) && $_GET["customizetemplate"]) {
	$return = "";
	if (!empty($_POST)) {
		$handle = fopen("../templates/".$_GET["customizetemplate"]."/settings.ini", "w");
		foreach ($_POST as $key => $value) {
			if ($key <> "save") {
				$value = str_replace("yes", "111yes111", $value);
				$value = str_replace("no", "111no111", $value);
				$value = str_replace("null", "111null111", $value);
				$value = str_replace("true", "111true111", $value);
				$value = str_replace("false", "111false111", $value);
				fwrite($handle, $key." = ".$value."\n");
			}
		}
		fclose($handle);

		$return = "<div class=\"actioncompleted\">Action completed</div>";
	}

	if (!file_exists("../templates/".$_GET["customizetemplate"]."/customize.txt")) {
		return "<div class=\"invalidlink\">Invalid page...</div>";
	}
	$handle = fopen("../templates/".$_GET["customizetemplate"]."/customize.txt", "rb");
	$contents = "";
	while (!feof($handle)) {
	  $contents = $contents.fread($handle, 8192);
	}
	fclose($handle);

	preg_match_all("/<input.*?type=\"text\".*?\/>/i", $contents, $inputtext);
	for ($i = 0; $i < count($inputtext[0]); $i++) {
		$contents = str_replace($inputtext[0][$i], $inputtext[0][$i]."<br /><br />", $contents);
	}
	$contents = str_replace("</select>", "</select><br /><br />", $contents);

	if (file_exists("../templates/".$_GET["customizetemplate"]."/settings.ini")) {
		$contents = str_replace("selected=\"selected\"", "", $contents);
		$contents = str_replace("checked=\"checked\"", "", $contents);
		preg_match_all("/<input.*?type=\"text\".*?value=\".*?\".*?\/>/i", $contents, $inputvalues);
		$fixedinputs = array();
		for ($i = 0; $i < count($inputvalues[0]); $i++) {
			preg_match_all("/value=\".*?\"/i", $inputvalues[0][$i], $inputs);
			$fixedinputs[$i] = str_replace($inputs[0][0], "", $inputvalues[0][$i]);
		}
		for ($i = 0; $i < count($fixedinputs); $i++) {
			$contents = str_replace($inputvalues[0][$i], $fixedinputs[$i], $contents);
		}

		$ini = parse_ini_file("../templates/".$_GET["customizetemplate"]."/settings.ini");

		foreach ($ini as $key => $value) {
			$value = str_replace("111yes111", "yes", $value);
			$value = str_replace("111no111", "no", $value);
			$value = str_replace("111null111", "null", $value);
			$value = str_replace("111true111", "true", $value);
			$value = str_replace("111false111", "false", $value);

			// set selected, checked, value= ...
			preg_match_all("/<input.*?type=\"text\".*?name=\"".$key."\".*?\/>/i", $contents, $inputvalues);
			if (count($inputvalues[0]) > 0) {
				$contents = str_replace("name=\"".$key."\"", "name=\"".$key."\" value=\"".$value."\"", $contents);
			}
			preg_match_all("/<select.*?name=\"".$key."\".*?>/i", $contents, $selects);
			if (count($selects[0]) > 0) {
				preg_match_all("/".$selects[0][0].".*?<\/select>/is", $contents, $selectvalues);
				if (count($selectvalues[0]) > 0) {
					preg_match_all("/<option.*?value=\"".$value."\"/i", $contents, $options);
					if (count($options[0]) > 0) {
						$replacement = str_replace($options[0][0], $options[0][0]." selected=\"selected\"", $selectvalues[0]);
						$contents = str_replace($selectvalues[0], $replacement[0], $contents);
					}
				}
			}
			preg_match_all("/<input.*?type=\"radio\".*?name=\"".$key."\".*?\/>/i", $contents, $inputvalues);
			if (count($inputvalues[0]) > 0) {
				$contents = str_replace("name=\"".$key."\"", "name=\"".$key."\" checked=\"checked\"", $contents);
			}
		}
	}

	return $return."<form id=\"frm\" action=\"".$_SERVER['REQUEST_URI']."\" method=\"post\"><fieldset>".$contents."<input type=\"submit\" name=\"save\" value=\"Set\" class=\"button\" /></fieldset></form>";
} else {
	include ("scripts/checkdir.php");
	
	$return="
	<form id=\"frm\" action=\"".$_SERVER['REQUEST_URI']."\" method=\"post\">
		<fieldset>
			<table>";
			$templateset = "";
			$alltemplates = mysql_query("select name from ".$tableprefix."templates where number='".($backend+1)."'");
			while ($template = mysql_fetch_array($alltemplates, MYSQL_ASSOC)) {
				$templateset = $template{'name'};
			}
			$templates = checkdir("../templates/");
			for ($i = 2; $i < count($templates); $i++) {
				$checked = "";
				if ($templates[$i] == $templateset) {
					$checked = "checked=\"checked\" ";
				}
				// check if template HAS customization file
				$customize = "";
				if (file_exists("../templates/".$templates[$i]."/customize.txt")) {
					$customize = "<td><a href=\"".$_SERVER['REQUEST_URI']."&amp;customizetemplate=".$templates[$i]."\">Advanced...</a></td>";
				}
				$return = $return."<tr><td><input type=\"radio\" name=\"name\" value=\"".$templates[$i]."\" ".$checked."/></td><td><img src=\"../templates/".$templates[$i]."/thumbnail.png\" alt=\"".$templates[$i]." thumbnail\" style=\"width: 150px; height: 100px;\" /></td><td>".$templates[$i]."</td>".$customize."</tr>";
			}
			$return = $return."
			</table>
			<br />
			<br />
			<input type=\"submit\" name=\"save\" value=\"Set\" class=\"button\" />
			<input type=\"hidden\" name=\"table\" value=\"templates\" />
			<input type=\"hidden\" name=\"number\" value=\"".($backend+1)."\" />
		</fieldset>
	</form>";
	return $output.$return;
}
?>
Return current item: Anantasoft Gazelle CMS