Re-write the naviagation agian - no more ajax menus, and it auto-selects the first secondary and first tertiary pages when clicking a higher level

This commit is contained in:
james 2010-09-23 16:17:24 +00:00
parent 2292af3206
commit 60c6235649
4 changed files with 143 additions and 173 deletions

View File

@ -312,4 +312,36 @@ $CWSFDivisions=array(
9=>"Physical & Mathematical Sciences" 9=>"Physical & Mathematical Sciences"
); );
//take SFIABDIRECTORY off of the current URL
$pageurl=substr($_SERVER['PHP_SELF'],strlen($config['SFIABDIRECTORY']));
//set things to 0 to start
$_SESSION['nav']['primary']=0;
$_SESSION['nav']['secondary']=0;
$_SESSION['nav']['tertiary']=0;
//this code figures out if the page we're on is in the navigation structure, and if so, where, and properly sets the primary, secondary and tertiary navigation variables
$q=mysql_query("SELECT * FROM rolestasks WHERE link='".mysql_real_escape_string($pageurl)."' AND conferencetype='{$conference['type']}'");
if($r=mysql_fetch_object($q)) {
//okay we found it, now get its full tree above it
$navTree=array();
upTree($r->id,&$navTree);
//go through each one, and set the SESSION vars
foreach($navTree AS $t) {
switch($t['level']) {
case 0: //primary nav
$_SESSION['nav']['primary']=$t['id'];
break;
case 1: //secondary nav
$_SESSION['nav']['secondary']=$t['id'];
break;
case 2: //tertiary nav
$_SESSION['nav']['tertiary']=$t['id'];
break;
}
}
}
else {
}

View File

@ -22,12 +22,13 @@
*/ */
?> ?>
<? <?
//functions contains all the common functions besides the header/footer functions
//must go before bootstrap becuase bootstrap needs some of the functions in it
require_once("common.inc.functions.php");
//bootstrap sets up the session, loads config params, etc, etc. //bootstrap sets up the session, loads config params, etc, etc.
require_once("common.inc.bootstrap.php"); require_once("common.inc.bootstrap.php");
//functions contains all the common functions besides the header/footer functions
require_once("common.inc.functions.php");
$HEADER_SENT=false; $HEADER_SENT=false;
function send_header($title="", $nav=null, $icon=null, $titletranslated=false) { function send_header($title="", $nav=null, $icon=null, $titletranslated=false) {
global $HEADER_SENT; global $HEADER_SENT;
@ -59,7 +60,6 @@ function send_header($title="", $nav=null, $icon=null, $titletranslated=false) {
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/sfiab.js"></script> <script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/sfiab.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/nav.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/tablesorter/jquery.tablesorter.min.js"></script> <script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/tablesorter/jquery.tablesorter.min.js"></script>
<script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/validate/jquery.validate.pack.js"></script> <script type="text/javascript" src="<?=$config['SFIABDIRECTORY']?>/js/validate/jquery.validate.pack.js"></script>
<script type="text/javascript"> <script type="text/javascript">
@ -236,19 +236,18 @@ if(is_array($_SESSION['roles'])) {
foreach($_SESSION['roles'] AS $roletype) { foreach($_SESSION['roles'] AS $roletype) {
$roleid=$roles[$roletype]['id']; $roleid=$roles[$roletype]['id'];
$q=mysql_query("SELECT * FROM rolestasks WHERE roles_id='$roleid' AND pid=0 AND conferencetype='{$conference['type']}' ORDER BY ord,task"); $q=mysql_query("SELECT * FROM rolestasks WHERE roles_id='$roleid' AND pid=0 AND conferencetype='{$conference['type']}' ORDER BY ord,task");
if(mysql_num_rows($q)==1) {
$setPrimaryNav=true;
}
$cl=""; $cl="";
while($r=mysql_fetch_object($q)) { while($r=mysql_fetch_object($q)) {
if($setPrimarynav) { if($_SESSION['nav']['primary'] == $r->id) {
$_SESSION['nav']['primary']=$r->id;
$cl="class=\"selected\""; $cl="class=\"selected\"";
} }
echo "<li id=\"primary_nav_{$r->id}\" $cl>"; else $cl="";
echo "<li $cl>";
if($r->link) $href=$config['SFIABDIRECTORY'].$r->link; if($r->link) $href=$config['SFIABDIRECTORY'].$r->link;
else $href="#"; else $href=$config['SFIABDIRECTORY']."/nav.php?id=$r->id";
echo "<a href=\"$href\" onclick=\"return taskNavLevel($r->id,0,0,0)\">".i18n($r->task)."</a>"; //echo "<a href=\"$href\" onclick=\"return taskNavLevel($r->id,0,0,0)\">".i18n($r->task)."</a>";
echo "<a href=\"$href\">".i18n($r->task)."</a>";
echo "</li>\n"; echo "</li>\n";
} }
} }
@ -288,52 +287,63 @@ if(array_key_exists('users_id', $_SESSION)) {
</ul> </ul>
</div> </div>
<div id="division-menu" class="clear"> <div id="division-menu" class="clear">
<?
$q=mysql_query("SELECT * FROM rolestasks WHERE pid='{$_SESSION['nav']['primary']}' AND level=1 AND conferencetype='{$conference['type']}' ORDER By ord,task");
echo mysql_error();
echo "<ul class=\"secondarynav\">";
$cl="";
while($r=mysql_fetch_object($q)) {
if($_SESSION['nav']['secondary'] == $r->id) {
$cl="class=\"selected\"";
}
else $cl="";
echo "<li $cl>";
//echo "<a href=\"#\" onclick=\"return taskNavLevel($r->id,$r->pid,$r->level)\">".i18n($r->task)."</a>";
if($r->link) $href=$config['SFIABDIRECTORY'].$r->link;
else $href=$config['SFIABDIRECTORY']."/nav.php?id=$r->id";
echo "<a href=\"$href\">".i18n($r->task)."</a>";
echo "</li>\n";
}
echo "</ul>\n";
?>
</div> </div>
</div> </div>
<div id="main" class="clear">
<div id="topic-menu">
<?
$q=mysql_query("SELECT * FROM rolestasks WHERE pid='{$_SESSION['nav']['secondary']}' AND level=2 AND conferencetype='{$conference['type']}' ORDER By ord,task");
echo "<ul class=\"topic-menu sfiab-menu\">";
while($r=mysql_fetch_object($q)) {
$cl="class=\"";
if($r->link)
$cl.="link ";
else
$cl.="heading ";
if($_SESSION['nav']['tertiary'] == $r->id) {
$cl.=" selected";
}
$cl.="\"";
echo "<li $cl><a href=\"".$config['SFIABDIRECTORY']."$r->link\">".i18n($r->task)."</a></li>\n";
}
echo "</ul>\n";
?>
</div>
<?
//if the page we're on isnt part of the navigation, then hide the secondary and tertiary menus
if(!($_SESSION['nav']['primary'] && $_SESSION['nav']['secondary'] && $_SESSION['nav']['tertiary'])) {
?>
<script type="text/javascript">
$(document).ready(function(){
$("#division-menu").hide();
$("#topic-menu").hide();
});
</script>
<? <?
//take SFIABDIRECTORY off of the current URL
$pageurl=substr($_SERVER['PHP_SELF'],strlen($config['SFIABDIRECTORY']));
$q=mysql_query("SELECT * FROM rolestasks WHERE link='".mysql_real_escape_string($pageurl)."' AND conferencetype='{$conference['type']}'");
if($r=mysql_fetch_object($q)) {
//okay we found it, now get its full tree above it
$navTree=array();
upTree($r->id,&$navTree);
//set things to 0 to start
$_SESSION['nav']['primary']=0;
$_SESSION['nav']['secondary']=0;
$_SESSION['nav']['tertiary']=0;
$_SESSION['nav']['tertiarylink']=0;
//go through each one, and set the SESSION vars
foreach($navTree AS $t) {
switch($t['level']) {
case 0: //primary nav
$_SESSION['nav']['primary']=$t['id'];
break;
case 1: //secondary nav
$_SESSION['nav']['secondary']=$t['id'];
break;
case 2: //tertiary nav heading
$_SESSION['nav']['tertiary']=$t['id'];
break;
case 3: //tertiary nav link
$_SESSION['nav']['tertiarylink']=$t['id'];
break;
}
}
echo "\n\n<script type=\"text/javascript\">";
//and once the page is ready, call the taskNavLevel function to fill everything out and select what needs to be selected
echo "$(document).ready(function(){\n";
$str = "taskNavLevel({$_SESSION['nav']['primary']}, {$_SESSION['nav']['secondary']}, {$_SESSION['nav']['tertiary']}, {$_SESSION['nav']['tertiarylink']});";
echo $str;
echo " });";
echo "</script>\n";
}
else {
} }
/* /*
if(is_array($nav)) { if(is_array($nav)) {
@ -348,12 +358,6 @@ if(is_array($nav)) {
echo '</div>'; echo '</div>';
} }
*/ */
?>
<div id="main" class="clear">
<div id="topic-menu">
</div>
<?
if(is_array($_SESSION['roles'])) { if(is_array($_SESSION['roles'])) {
$has_config = array_key_exists('config', $_SESSION['roles']); $has_config = array_key_exists('config', $_SESSION['roles']);

View File

@ -1,45 +0,0 @@
function taskNavLevel(l1,l2,l3,l4) {
if(l2) {
//we have a secondary click, which implies we also have a primary nav selected
//we may or may not have l3 or l4 though, so they are handled separately below
$("#division-menu").load(config.SFIABDIRECTORY+"/nav.php?level=1&id="+l1,null,function() {
$("#division-menu").show();
// $("#tertiarymenu_accordion").accordion("destroy");
$("#topic-menu").load(config.SFIABDIRECTORY+"/nav.php?level=2&id="+l2,null,function() {
// $("#tertiarymenu_accordion").accordion({clearStyle: true, collapsible: true, active: false}); //"option", "collapsible", true);
$("#topic-menu").show();
$(".primarynav-selected").removeClass("primarynav-selected");
$("#primary_nav_"+l1).addClass("primarynav-selected");
$(".secondarynav-selected").removeClass("secondarynav-selected");
$("#secondary_nav_"+l2).addClass("secondarynav-selected");
//if we have a 3rd level nav, open up the accordion to the appropriate place
if(l3) {
// $("#tertiarymenu_accordion").accordion("activate",$("#tertiary_nav_"+l3));
}
//if we have a 4th level nav, set the selected class on the appropriate item in the list
if(l4) {
$(".tertiarylinknav-selected").removeClass("tertiarylinknav-selected");
$("#tertiarylink_nav_"+l4).addClass("tertiarylinknav-selected");
}
});
});
}
else {
//only the primary link clicked, so show the secondary, and thats it.
$("#division-menu").load(config.SFIABDIRECTORY+"/nav.php?level=1&id="+l1,null,function() {
$(".primarynav-selected").removeClass("primarynav-selected");
$("#primary_nav_"+l1).addClass("primarynav-selected");
//show the secondary
$("#division-menu").show();
//and hide the tertiary
// $("#topic-menu").hide();
});
}
}

83
nav.php
View File

@ -22,63 +22,42 @@
?> ?>
<? <?
include "common.inc.php"; include "common.inc.php";
$id=intval($_GET['id']);
$level=intval($_GET['level']);
if($id && $level) { //if we're here, its because we didnt have a link to click, so we need to figure out the first topic-level (tertiary) menu item to redirect to
switch($level) {
case 1: //populate the scecondary menu $id=intval($_GET['id']);
if($_SESSION['nav']['primary']!=$id) { $q=mysql_query("SELECT * FROM rolestasks WHERE id='$id'");
$r=mysql_fetch_object($q);
//print_r($r);
//we clicked on a channel-level (primary) nav, so we need to get the FIRST secondary under it, and teh FIRST tertiary under that.
if($level==0) {
$primary=$id;
$q2=mysql_query("SELECT * FROM rolestasks WHERE pid='$id' ORDER BY ord LIMIT 1");
$r2=mysql_fetch_object($q2);
$secondary=$r2->id;
$_SESSION['nav']['primary']=$id; $_SESSION['nav']['primary']=$id;
} }
unset($_SESSION['nav']['secondary']); else if($level==1) {
unset($_SESSION['nav']['tertiary']); $secondary=$id;
unset($_SESSION['nav']['tertiarylink']);
$q=mysql_query("SELECT * FROM rolestasks WHERE pid='$id' AND level=1 AND conferencetype='{$conference['type']}' ORDER By ord,task");
echo mysql_error();
echo "<ul class=\"secondarynav\">";
$cl="";
while($r=mysql_fetch_object($q)) {
if($_SESSION['nav']['secondary'] == $r->id) {
$cl="class=\"secondarynav-selected\"";
} }
else $cl=""; $_SESSION['nav']['secondary']=$secondary;
echo "<li id=\"secondary_nav_{$r->id}\" $cl>";
//echo "<a href=\"#\" onclick=\"return taskNavLevel($r->id,$r->pid,$r->level)\">".i18n($r->task)."</a>";
echo "<a href=\"#\" onclick=\"return taskNavLevel($r->pid, $r->id)\">".i18n($r->task)."</a>";
echo "</li>\n";
}
echo "</ul>\n";
break;
case 2: //populate the tertiary menu //now we have a secondary whether it was a primary clicked on, or a secondary clicked on, so now we just get the tertiary (topic) link
$_SESSION['nav']['secondary']=$id; $q3=mysql_query("SELECT * FROM rolestasks WHERE pid='$secondary' AND link!='' ORDER BY ord LIMIT 1");
unset($_SESSION['nav']['tertiary']); if($r3=mysql_fetch_object($q3)) {
unset($_SESSION['nav']['tertiarylink']); $tertiary=$r3->id;
$q=mysql_query("SELECT * FROM rolestasks WHERE pid='$id' AND level=2 AND conferencetype='{$conference['type']}' ORDER By ord,task"); $_SESSION['nav']['tertiary']=$tertiary;
echo "<ul class=\"topic-menu sfiab-menu\">";
while($r=mysql_fetch_object($q)) { header("Location: {$config['SFIABDIRECTORY']}{$r3->link}");
$link_style = 'link'; // Sep 09, 2010 MK: Class name needs to be derived from the data to allow for subtitles, separators etc.
echo "<li id=\"tertiarylink_nav_{$r->id}\" class=\"$link_style\"><a href=\"".$config['SFIABDIRECTORY']."$r->link\">".i18n($r->task)."</a></li>\n";
/*
if($r->link) {
echo "<h3 id=\"tertiary_nav_{$r->id}\"><a href=\"{$config['SFIABDIRECTORY']}$r->link\">".i18n("$r->task")."</a></h3>\n";
} else { } else {
echo "<h3 id=\"tertiary_nav_{$r->id}\">".i18n("$r->task")."</h3>\n"; send_header("Navigation Error");
echo error("Hmm something seems mis-configured. We hit a topic-level menu that doesnt have any linkable items")."<br />";
echo "Perhaps you should fix this in <a href=\"".$config['SFIABDIRECTORY']."/super/roletasks.php\">Superuser Role Tasks Setup</a>";
echo "<br /><br />";
echo "DEBUG:";
print_r($r);
send_footer();
} }
*/
/*
echo "<ul class=\"topic-menu sfiab-menu\">";
$q2=mysql_query("SELECT * FROM rolestasks WHERE pid='$r->id' AND level=3 AND conferencetype='{$conference['type']}' ORDER BY ord,task");
while($r2=mysql_fetch_object($q2)) {
echo "<li id=\"tertiarylink_nav_{$r2->id}\"><a href=\"".$config['SFIABDIRECTORY']."$r2->link\">".i18n($r2->task)."</a></li>\n";
}
echo "</ul>";
*/
}
echo "</ul>\n";
break;
}
}
?>