Have a look at content management concepts. Essentially you store all of your page content in a database. When a page is requested, you serve it from the database. That page can hold lots of information, including who should see it (this isn't necessarily in the page content table, but it does relate to it so it can be anywhere in the database). Then, when the page is called, show it if it is to be shown.
Obviously, this same concept can be applied to the navigation as the pages you want your users to visit are the same ones you want your users to see. So, given that all of your pages are in the content table, select them all (based on criteria) and create a navigation from what you know they should have access to based on their profile and the pages in the page_content table.
For now, for what you got going on, I would look at something a little more simplified...
Code: Select all
<?php
function buildNavigation($page)
{
$return = '';
//open the table..
$return .= '<table class="temp_nav_bar">
<tbody>
<tr>';
if (isset($_SESSION['USERID']))
{
// User is logged in
$return .= '<td class="userid">' . $_SESSION['USERID'] . '</td>';
// Show a logout link if not on the logout page
if ($page != 'Logout')
{
$return .= '<td><a href="logout.php">Log out</a></td>';
}
/**
* I would seriously consider using the actual link name instead
* of the link text name, as it would be a lot easier for comparison
*/
//EVERYONE
if ($page != "Job List")
{
$return .= '<td><a href="index.php">Job List</a></td>';
}
// Are we an admin?
if ($_SESSION['USERID'] == 'admin')
{
// yes we are
if ($page != 'Company and Post Administration')
{
$return .= '<td><a href="administration.php">Administration</a></td>';
}
if ($page != 'Edit Contact Info')
{
$return .= '<td><a href="contactedit.php">Edit Contact Info</a></td>';
}
if ($page != "Post New Jobs")
{
$return .= '<td><a href="post_job.php">Post Job</a></td>';
}
}
}
else
{
$return .= '<td><a href="login.php">Log in</a></td>';
}
//close the table
$return .= '</tr>
</tbody>
</table>';
return $return;
}
?>