Location: PHPKode > projects > chillyCMS > chillyCMS/admin/design.include.php
<?php
//#################################################################################################
//	Design helper functions
//#################################################################################################
//	chillyCMS - Content Management System
//	Copyright (C) 2008
//	Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//	
//	This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
//	load_templates()
//	uploadform()
//	upload_template($src_file)
//	activate_template($name)
//	delete_template($name)
//#################################################################################################
defined('DOIT') or die('Restricted access');

//Load Templates///////////////////////////////////////////////////////////////////////////////////
function load_templates() {
	global $l_des,$l_gen,$settings;
	$dir=PATH."/templates/";
	$templates = false;
 	if (is_dir($dir) && $dh = opendir($dir)) {
	$templates .= "<table class=\"realtable\" cellspacing='0' width='100%'>\n".
	"<tr>\n".
	"<th class='center'>$l_des[lbl_preview]</th>\n".
	"<th class='center'>$l_des[lbl_name]</th>\n".
	"<th class='center'>$l_des[lbl_author]</th>\n".
	"<th width='100'>$l_des[lbl_position]</th>\n".
	"<th class='center' width='80'>$l_des[lbl_version]</th>\n".
	"<th width='80' class='center'>$l_gen[lbl_status]</th>\n".
	"<th width='80' class='center'>$l_gen[lbl_delete]</th>\n".
	"</tr>\n";
	//read content of template dir
	$style="even";
	while (($file = readdir($dh)) !== false) {
		if ($file != "." and $file != ".." and filetype($dir.$file)=="dir") {
			//for each template
			if ($dh2 = opendir($dir.$file)) {
				$found=false;
				$positions=false;
				//get config file
				if (file_exists(PATH."/templates/$file/config.php")) {
					include(PATH."/templates/$file/config.php");
					//only show "real" template files
					if (is_array($positions)) {
						if ($style=="odd") { $style="even"; } else { $style="odd"; }
						$templates .= "<tr class='$style'>\n";
						//read preview picture
						while (($preview = readdir($dh2)) !== false) {
							if ($preview=="preview.png") {
								$found=true;
								$previewpath="../templates/$file/$preview";
								$templates .= "<td class='templatepreview'><img src=".
								"'$previewpath' alt='preview' /></td>\n";
							}
						}
						if ($found==false) { $templates .= $l_des["nopreview"]; }
						//Filename
						$templates .= "<td>".escape_html($file)."</td>\n".
						"<td>".escape_html($author)."</td>\n".
						"<td><ul>\n";
						if (!empty($positions)) {
							$positions=array_map("escape_html",$positions);
							foreach ($positions as $pos) {
								$templates .= "<li>$pos</li>\n";
							}
						}
						$templates .= "</ul></td>\n".
						"<td>".escape_html($version)."</td>\n".
						"<td>\n";
						//Status
						if (strtolower($settings["template"])==strtolower($file)) {
							$templates .= "<a class='useractive'></a>\n".
							"</td>\n".
							"<td></td>\n".
							"</tr>\n";
						} else {
							//activate
							$templates .= "<form method='post' action='design.site.php'>\n".
							"<input type='hidden' name='action' value='activate' />\n".
							"<input type='hidden' name='name' value='$file' />\n".
							"<input type='submit' value=\" \" class='userinactive' ".
							"title='$l_des[tip_choose]' />\n".
							"</form>\n".
							"</td>\n".
							//delete
							"<td>\n".
							"<form method='post' action='design.site.php'>\n".
							"<input type='hidden' name='action' value='delete' />\n".
							"<input type='hidden' name='name' value='$file' />\n".
							"<input type='submit' value=\" \" class='delete' ".
							js_confirm_link($file.$l_gen["pop_del"]).
							"title='$l_gen[lbl_delete]' />\n".
							"</form>\n".
							"</td>\n".
							"</tr>\n";
						}	
					}
				}
			}			
		}
	}
	$templates .= "</table><br />";
	closedir($dh);
	}
	return $templates;
}
//Activate template////////////////////////////////////////////////////////////////////////////////
function activate_template($name) {
	global $l_des,$page;
	$name = escape($name);
	$sql="update site_settings set `value`='$name' where `key`='template'";
	if ($page->query($sql)) {
		$msg = array("$l_des[msg_activ_ok] \"$name\"","good");
	} else {
		$msg = array("$l_des[msg_activ_err] \"$name\"","bad");
	}
	return $msg;
}
//Delete Template//////////////////////////////////////////////////////////////////////////////////
function delete_template($name) {
	global $l_des,$page,$settings;

	if ($settings["template"]!=$name) {
		$name = escape($name);
		$name = cut_doubledots($name);
		$dir=PATH."/templates/$name";
		if (delete_recursively($dir)) { return array("$l_des[msg_del_ok] \"$name\"","good"); }
		else { return array("$l_des[msg_del_err] \"$name\"","bad"); }
	} else {
		return array($l_des["msg_delact_err"],"bad");
	}
} ?>
Return current item: chillyCMS