<?PHP
#
#   FILE:  StdPageEnd.html
#
#   Part of the Collection Workflow Integration System (CWIS)
#   Copyright 2012 Internet Scout Project
#   http://scout.wisc.edu/
#

# ----- LOCAL FUNCTIONS ------------------------------------------------------

/**
 * Display the given navigation items.
 * @param array $Items navigation items (item label => link)
 * @param array $PossibleExclusions exclusions (item link => exlude item)
 * @param string $Event navigation modification event
 * @param mixed $DisplayFunc callback used to display links
 * @return void
 */
function DisplayNavItems($Items, $PossibleExclusions, $Event, $DisplayFunc)
{
    # filter out nav items based on system configuration
    foreach ($Items as $Label => $Link)
    {
        if (isset($PossibleExclusions[$Link]) && !$PossibleExclusions[$Link])
        {
            unset($Items[$Label]);
        }
    }

    # signal event to give plugins etc a chance to modify nav item list
    $SignalResult = $GLOBALS["AF"]->SignalEvent($Event, array(
        "NavItems" => $Items));
    $Items = $SignalResult["NavItems"];

    # display nav items
    foreach ($Items as $Label => $Link)
    {
        if (preg_match("/^[a-zA-Z0-9_]+$/", $Link)) {  $Link = "index.php?P=".$Link;  }
        $DisplayFunc($Link, $Label);
    }
}

/**
 * Display a single navigation link.
 * @param string $Link the URL of the link (will be escaped)
 * @param string $Label the text for the link (should already be escaped)
 * @return void
 */
function DisplayNavItem($Link, $Label)
{
?><a href="<?PHP print defaulthtmlentities($Link);  ?>"><?PHP print $Label;  ?></a><?PHP
}

# ----- MAIN -----------------------------------------------------------------

$PrimaryNavItems = array(
    # Nav Item Label => Nav Item Link
    "<b>Register</b>" => "RegisterPortal",
    "Home" => "Home",
    "Browse Resources" => "BrowseResources",
    "Get Recommendations" => "RecommendResources",
    "Forums" => "Forums",
    "About" => "About",
    "Advanced Search" => "Advanced");

$SecondaryNavItems = array(
    # Nav Item Label => Nav Item Link
    "Preferences" => "Preferences",
    "Accessibility" => "AccessPreferences",
    "Metadata Tool" => "MDHome",
    "Administration" => "SysAdmin",
    "Edit User Account" => "SelectEditUser",
    "Log Out" => "UserLogout");

$NavExclusions = array(
    # Nav Item Link => Whether to Display
    "Preferences" => $G_User->IsLoggedIn(),
    "RecommendResources" => ($G_SysConfig->ResourceRatingsEnabled()
                             && $G_User->IsLoggedIn()),
    "Forums" => $G_SysConfig->ForumsEnabled(),
    "RegisterPortal" => ($G_User->HasPriv(PRIV_SYSADMIN)
                         && !$G_SysConfig->HasRegistered()),
    "AccessPreferences" => $G_SysConfig->AccessibilityWizardEnabled(),
    "MDHome" => $User->HasPriv(PRIV_RESOURCEADMIN, PRIV_CLASSADMIN,
                               PRIV_MYRESOURCEADMIN, PRIV_NAMEADMIN, PRIV_RELEASEADMIN),
    "SysAdmin" => $User->HasPriv(PRIV_SYSADMIN, PRIV_COLLECTIONADMIN,
                                 PRIV_USERADMIN),
    "SelectEditUser" => $User->HasPriv(PRIV_SYSADMIN, PRIV_USERADMIN),
    "UserLogout" => $G_User->IsLoggedIn());

?>

</div>
<div id="PageBottom">
	<div class="TopNBottom">
        <img id="Logo" src="interface/LowVision/images/CWIS--Logo.gif" width="88" height="30" alt="CWIS" style="float:right;">
	    <?PHP print $SysConfig->LegalNotice(); ?>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a href="index.php?P=LeaveFeedback">Leave Feedback</a>.
	</div>
	<?php  if ($User->HasPriv(PRIV_SYSADMIN)) {  ?>
	<div class="TopNBottom"><i>
				page generation time: <?PHP  global $PageGenerationBeginTime;  printf("%.3f", microtime(TRUE) - $PageGenerationBeginTime);  ?> seconds
				&nbsp;&nbsp;&nbsp;&nbsp;
				<?PHP  print(SoftwareIsCWIS() ? "CWIS" : "SPT");  ?> version: <?PHP  global $SPT_SoftwareVersionToDisplay;  print($SPT_SoftwareVersionToDisplay);  ?>
				&nbsp;&nbsp;&nbsp;&nbsp;
				database name: <?PHP  global $SPT_DBName;  print($SPT_DBName);  ?>
			</i></div>
	<?php  }  ?>
</div>

</div>
<div id="PageNav">

	<div class="NavDiv" id="MainSearch">
		<div class="NavDivTop">Search</div>
		<form method="POST" action="index.php?P=AdvancedSearch">
		<div>
			<input type="text" name="F_SearchString" size="17" maxlength="120" value=""><br>
			<input type="submit" value="Search">
		</div>
		</form>
	</div>

	<a name="Nav"></a>
	<div id="MainNavOptions" class="NavDiv">
		<div class="NavDivTop">Navigate</div>
<?PHP

DisplayNavItems(
    $PrimaryNavItems,
    $NavExclusions,
    "EVENT_MODIFY_PRIMARY_NAV",
    "DisplayNavItem");
DisplayNavItems(
    $SecondaryNavItems,
    $NavExclusions,
    "EVENT_MODIFY_SECONDARY_NAV",
    "DisplayNavItem");
?>

	</div>

        <?php  if (InMetadataTool()) {  include("interface/LowVision/SPT--MDSideNav.html");  } ?>

<?php  if ($User->IsLoggedIn() == FALSE) {  ?>

	<div id="MainLogin" class="NavDiv">
		<div class="NavDivTop">Login</div>
		<form method="post" action="index.php?P=UserLogin">
		<label for="UserName">User Name</label>
		<input type="text" size="12" maxlength="24" name="F_UserName" id="UserName" style="font-size: 11px; display: block; margin: 0px auto;">
		<label for="Password">Password</label>
		<input type="password" size="12" maxlength="24" name="F_Password" id="Password" style="font-size: 11px; display: block; margin: 0px auto;"><br>
		<input style="display: block; margin: 0px auto;" type="submit" value="Login"><br>

		<a href="index.php?P=RequestAccount" class="small">Sign up for an account.</a>

		</div>
		</form>

<?php } ?>
    <div id="MainHelpLink"><a href="index.php?P=Help">Help</a></div>
	<a href="" onclick="toggle('ReNav'); NavDisapeer(); return false;" id="NoNav">Hide Navigation</a>
	</div>
</div>
</div>
</body>
</html>
