Location: PHPKode > projects > ACollab > include/lib/folders.inc.php
<?php

if (!defined('AC_INCLUDE_PATH')) { exit; }

/* prints out the given $folders as an XHTML list */
/* $folders: folders given, where the key is the folder_id */
/* $folder_id: the current folder id */
function print_folders($folders, $current_folder_id = 0, $depth = 0) {
	if (!is_array($folders[$current_folder_id]['children'])) {
		return;
	}

	if ($current_folder_id == 0) {
		echo '<div style="margin-left: 10px;">';
	}

	foreach($folders[$current_folder_id]['children'] as $child_folder_id) {
		//echo str_repeat('&nbsp;', $depth * 4);
		echo '<ul class="folders">';
		if ($child_folder_id == $_REQUEST['id']) {
			echo '<li class="open">';
			echo '<strong>'.$folders[$child_folder_id]['title'].'</strong>';
		} else {
			echo '<li class="close">';
			echo '<a href="'.$_SERVER['PHP_SELF'].'?id='.$child_folder_id.'">'.$folders[$child_folder_id]['title'].'</a>';
		}

		print_folders($folders, $child_folder_id, $depth +1);
		echo '</li>';
		echo '</ul>';
	}

	if ($current_folder_id == 0) {
		echo '</div>';
	}
}

/* generates a <select> of the given $folder */
/* $folder_id: the current folder id to start the traversal */
/* $current_folder_id: the current folder id, will be set to "selected" if $exclude is false o/w the parent will be selected */
/* $exclude: whether or not the children of $current_folder_id should be excluded or not. */
/* $depth: just keeps track of how deep the $folder_id is */
function select_folders($folders, $folder_id, $current_folder_id, $exclude, $depth=0) {
	if ($folder_id == 0 && is_array($folders[0]['children'])) {
		foreach ($folders[0]['children'] as $child_folder_id) {
			select_folders($folders, $child_folder_id, $current_folder_id, $exclude);
		}
	} else {
		if ($exclude && ($folder_id == $current_folder_id)) {
			return;
		}
		echo '<option value="'.$folder_id.'"';

		if ($exclude && is_array($folders[$folder_id]['children']) && in_array($current_folder_id, $folders[$folder_id]['children'])) {
			echo ' selected="selected"';
		} else if (!$exclude && ($folder_id == $current_folder_id)) {
			echo ' selected="selected"';
		}
		echo '>';
		echo str_repeat("&nbsp;", $depth*4);
		echo $folders[$folder_id]['title'].'</option>';

		if (is_array($folders[$folder_id]['children'])) {
			foreach($folders[$folder_id]['children'] as $child_folder_id) {
				select_folders($folders, $child_folder_id, $current_folder_id, $exclude, $depth+1);
			}
		}
	}
}

function get_folders() {
	global $db;

	/* get all the folders: */
	/* $folders[folder_id] = array(title, parent_folder_id, [array(children)]) */
	$sql = "SELECT * FROM ".TABLE_PREFIX."folders WHERE group_id=$_SESSION[group_id] GROUP BY parent_folder_id, title";
	$result = mysql_query($sql, $db);

	if (!$result) {
		return FALSE;
	}

	while ($row = mysql_fetch_assoc($result)) {
		$folders[$row['folder_id']]['title']             = $row['title'];
		$folders[$row['folder_id']]['parent_folder_id']  = $row['parent_folder_id'];

		if ($row['parent_folder_id'] > 0) {
			$folders[$row['parent_folder_id']]['children'][] = $row['folder_id'];
		} else {
			$folders[0]['children'][] = $row['folder_id'];
		}
	}
	//sort($folders);
	return $folders;
}

/* applies $theme to all the sub-categories recursively. */
/* returns an array of all the subcategories */
function recursive_get_subcategories($category_parent_id) {
	static $categories;
	if (!isset($categories)) {
		$categories = get_categories();
	}

	$children = array();
	if (is_array($categories[$category_parent_id]['children'])) {
		$children = $categories[$category_parent_id]['children'];
		foreach ($categories[$category_parent_id]['children'] as $category_child_id) {
			if ($category_child_id) {
				$children =  array_merge($children, recursive_get_subcategories($category_child_id));
			}
		}
	}
	return $children;
}

/* determines whther the user user has a personal folder or not */
function has_private_folder($member_id) {
	global $db;

	$sql = "SELECT private_folder FROM ".TABLE_PREFIX."groups_members WHERE member_id=$member_id AND group_id=$_SESSION[group_id]";
	$result = mysql_query($sql, $db);
	$row = mysql_fetch_assoc($result);

	if ($row['private_folder'] == 'n') {
		return FALSE;
	}

	return TRUE;
}

?>
Return current item: ACollab