So the addition of the permissions are all working. The users have permissions, the groups have permissions we have lots of permissions in the database.

So how do we use them? To do this we first need to get the permissions out of the database and into a format that I can quickly compare against. I am going to add the individual items into an array for further comparison later.

$per_array = array(); //Create the per_array array. 

/* SQL to get permission */
$sql = "SELECT `id`, `permission` FROM `users` WHERE `user` = '$user' LIMIT 1 ";
$results = mysql_query($sql)
	or die("Error getting user permissions.");
$row = mysql_fetch_array($results);

/* Explode the text field into an array. */
$tmp = explode(":",$row['permission']);

/* for each item, add it into a user permi*/
foreach($tmp as $t) {
	if(!in_array($t, $per_array)) {
		$per_array[] = $t;
	} //if not in array
} //foreach

Now if I want to check if a user has access to something I can run the following to check for a permission

if(in_array("m_instructor_management",$per_array)) {
	//Permission Allowed
}

Now the locations are a little bit difficult to search for as the values are id_ before the permission group and in the event of a menu item that may cover multiple locations I dont want to have to do a look up for each location. So to accommodate this I wrote a function that will check if a string matches any of the array items and returns appropriately.

function partialArraySearch($needle, $haystack) {
	foreach ($haystack as $straw) {
		if (strpos($straw, $needle) !== false){
			return true;
		} //if check for strpos
	}
	return false;
}

to check for access to any location timetable the command would be

if(partialArraySearch("l_class_management",$per_array)) {
	//Permission Allowed
}