<?php

$dirlist = scandir("/var/projects/trac");

$projects = array();
foreach ($dirlist as $file) {
	if ($file[0]!=".") {
		$object=array();
		$object['filename'] = $file;
		$ini_array = array();
		$ini_data = file("/var/projects/trac/".$file."/conf/trac.ini");
		
		$projectsection = FALSE;
		foreach ($ini_data as $ini_line) {
			if (trim($ini_line) == "[project]") {
				$projectsection = TRUE;		
			} else if ($projectsection && (1 == preg_match("/^\[.*\]$/", trim($ini_line)))) {
				$projectsection = FALSE;
			} else if ($projectsection) { 
				list($key, $value) = split("=", $ini_line);
				$ini_array[trim($key)] = trim($value);
			}
		}

		if (isset($ini_array['public']) && ($ini_array['public'] == "true")) {

			$object['name'] = $ini_array['name'];
			if ($object['name']=="") $object['name'] = $file;
			
			$object['descr'] = $ini_array['descr'];
			
			$projects[$file]=$object;
		}
	}
}

$smarty->assign("projects", $projects);


$output = $smarty->fetch("projects.tpl");
$smarty->assign("title", "Projects");
$smarty->assign("body", $output);

$sidebar = file_get_contents("../static/fragments/Projects-secondary.txt");
$smarty->assign("secondary", $sidebar);

?>