Location: PHPKode > projects > chillyCMS > chillyCMS/modules/cssgallery/backend.php
<?php
defined('DOIT') or die('Restricted access');

//settings are passed to this file in the variable $modsettings formatted as a string
$settingsarray=explode(',', $modsettings);
if ($settingsarray[0]!="") {
	$activefolder=$settingsarray[0];
}
$thumbapp=$settingsarray[1];
if ($thumbapp=="") { $thumbapp="_small"; }
$currents=$folders=array();
$depth = 0;
global $id,$page;

if (isset($_GET["folder"]) && $_GET["action"]=="chdir") {
	$activefolder=no_semicola($_GET["folder"]);
	$sql="update site_content set settings='$activefolder' where id=$id";
	$page->query($sql);
}
$editform .= "<input type='hidden' name='activefolder' value='$activefolder'/>";
if($writeright) {
	//Options to show in frontend
	$editform .= "<br /><p>$mod_cssgallery[lbl_whichfolder]</p><br />";
	$editform .= show_folders($activefolder,$currents,$folders,$editform);
	//appendix for thumbnails
	$editform .= "<div class='clr'></div><br />".
	"<p>Thumbnail Appendix: (no colons please!)</p>".
	"<input type='text' name='thumbappendix' value='$thumbapp' />";
} else {
	$editform .= $l_edit["msg_nowrite"]."<br /><br />".
	$mod_cssgallery["lbl_showfolder"]." $activefolder";
}

//since the data is to be saved in an array, the order is important!
$specialsettings="activefolder,thumbappendix";

///////////////////////////////////////////////////////////////////////////////////////////////////
function show_folders($activefolder,$currents,$folders,&$editform) {	//TODO: aktivieren eines aktiven items abfangen
	global $id;
	$editform .= "\t\t<div class='filelist_big'>\n".
	"\t\t\t<ul>\n";
	//Print link to media folder
	$editform .= "\t\t\t\t<li><span class='folder'></span><a class='folderlink'";
	if ($activefolder=="../media") {
		$editform .= ">media<span class='imageactive' style='float:right;cursor:default;'></span></a>\n";
	} else {
		$editform .= " href='edit.site.php?id=$id&amp;action=chdir&amp;folder=../media'>media".
		"<span class='imageinactive' style='float:right;'></span></a>\n";
	}
	$depth=0;
	$editform .= print_recursive("../media",&$depth,$activefolder,$currents,$folders);
	$editform .= "\t\t\t\t</li>\n".
	"\t\t\t</ul>\n".
	"\t\t</div>\n";
}
function print_recursive($path,&$depth,$activefolder,$currents,$folders) {
	global $id,$mysession,$is_admin,$l_media,$l_gen,$page;
	$result = $files = array();
	$handle = opendir($path);
	$printresult = '';
	array_push($currents,$activefolder);
	//xhtml conformity: tab generated code
	$tabs="\t\t\t\t";
	for ($i=0;$i<$depth;$i++) { $tabs.="\t"; }
	//does the directory exist and can it be accessed?
	if ($handle) {
	//is there any content?
	while (false !== ($file = readdir($handle))) {
	//file is not the folder itself or the parent folder
	if ($file != "." && $file != "..") {
		$name = $path."/".$file;
		$printname=substr($name,strlen($path)+1);
		$children=0;
		//"file" is a folder
		if (is_dir($name)) {
			array_push($folders,$name);
			//is the user allowed to see the folder? if not stop recursing into it
			$foldername=explode("/",$name);
			$myfolder=array_pop($foldername);
			$sql="select gid from system_groups where name='$myfolder' limit 1";
			$page->query($sql);
			$result = $page->db->getdata();
			//$result = db_query("select gid from system_groups where name='$myfolder' limit 1");
			$gid=intval($result["gid"]);
			//If the user is in that group show him the folder
			if ($is_admin or $gid>2) {
				//increment recursion depth
				$depth++;
				//only open new ul if folder contains children
				$printresult .= "$tabs\t<ul>\n";
				$children++;
				//is it the chosen folder?
				$printresult .= "$tabs\t<li style='margin-left:".($depth*20)."px'>\n".
				"$tabs\t\t<span class='folder'></span><a class='folderlink' ";
				if($name==$activefolder) {
					array_push($currents, $name);
					$printresult .= ">$printname".
					"<span class='imageactive' style='float:right;cursor:default;'></span>";		
				} else {
					$printresult .= "href='edit.site.php?id=$id&amp;action=chdir&amp;".
					"folder=$name'>$printname".
					"<span class='imageinactive' style='float:right;'></span>";
				}
				$printresult .= "</a>\n";
				//read directory content
				$ar = print_recursive($name,&$depth,$activefolder,$currents,$folders);
				//only close ul tag if there were any children
				if ($children>0) {
					$printresult .= "$tabs\t</li>\n";
				}
				$printresult .= "$tabs\t</ul>\n";
				//Decrement recursion depth
				$depth--;
			}
		}
	}
	}
	asort($files);
	foreach ($files as $output) {
		$printresult .= $output;
	}	
	}
	closedir($handle);
	return $printresult; 
}
?>
Return current item: chillyCMS