From e8c8bf33feb3ecacf78bc4f6a087c8e547ef0fd0 Mon Sep 17 00:00:00 2001 From: james Date: Thu, 15 Jul 2010 21:24:10 +0000 Subject: [PATCH] Fix some nav issues and start the task of detecting where in teh nav we are if we didnt navigate to the page through the links Some general formatting cleanups on the common.inc too --- common.inc.php | 87 +++++++++++++++++++++++++++----------------------- nav.php | 6 ++-- 2 files changed, 51 insertions(+), 42 deletions(-) diff --git a/common.inc.php b/common.inc.php index 9166cc6..e8e8408 100644 --- a/common.inc.php +++ b/common.inc.php @@ -310,48 +310,37 @@ if($_GET['switchlanguage']) { } } -function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") -{ +function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") { if(!$str) return ""; - if($forcelang) - { + if($forcelang) { $savelang=$_SESSION['lang']; $_SESSION['lang']=$forcelang; } - if($_SESSION['lang']) - { - if($_SESSION['lang']=="en") - { - for($x=1;$x<=count($args);$x++) - { + if($_SESSION['lang']) { + if($_SESSION['lang']=="en") { + for($x=1;$x<=count($args);$x++) { $str=str_replace("%$x",$args[$x-1],$str); } if($forcelang) $_SESSION['lang']=$savelang; return $str; } - else - { + else { $q=mysql_query("SELECT * FROM translations WHERE lang='".$_SESSION['lang']."' AND strmd5='".md5($str)."'"); - if($r=@mysql_fetch_object($q)) - { - if($r->val) - { + if($r=@mysql_fetch_object($q)) { + if($r->val) { $ret=$r->val; - for($x=1;$x<=count($args);$x++) - { + for($x=1;$x<=count($args);$x++) { $ret=str_replace("%$x",$args[$x-1],$ret); } if($forcelang) $_SESSION['lang']=$savelang; return $ret; } - else - { - for($x=1;$x<=count($args);$x++) - { + else { + for($x=1;$x<=count($args);$x++) { $str=str_replace("%$x",$args[$x-1],$str); } if($forcelang) $_SESSION['lang']=$savelang; @@ -359,14 +348,11 @@ function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") } } - else - { - if(count($argsdesc)) - { + else { + if(count($argsdesc)) { $argsdescstring=""; $n=1; - foreach($argsdesc AS $ad) - { + foreach($argsdesc AS $ad) { $argsdescstring.="%$n=$ad, "; $n++; } @@ -377,8 +363,7 @@ function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") $argsdescstring="null"; mysql_query("INSERT INTO translations (lang,strmd5,str,argsdesc) VALUES ('".$_SESSION['lang']."','".md5($str)."','".mysql_escape_string($str)."',$argsdescstring)"); - for($x=1;$x<=count($args);$x++) - { + for($x=1;$x<=count($args);$x++) { $str=str_replace("%$x",$args[$x-1],$str); } if($forcelang) $_SESSION['lang']=$savelang; @@ -386,16 +371,14 @@ function i18n($str,$args=array(),$argsdesc=array(),$forcelang="") } } } - else - { + else { //no language set, assume english if($forcelang) $_SESSION['lang']=$savelang; return $str; } } -function error($str,$type="normal") -{ +function error($str,$type="normal") { if($type=="normal") return "
$str

"; else if($type=="inline") @@ -403,24 +386,21 @@ function error($str,$type="normal") } -function notice($str,$type="normal") -{ +function notice($str,$type="normal") { if($type=="normal") return "
$str

"; else if($type=="inline") return "$str
"; } -function happy($str,$type="normal") -{ +function happy($str,$type="normal") { if($type=="normal") return "
$str

"; else if($type=="inline") return "$str
"; } -function display_messages() -{ +function display_messages() { /* Dump any messages in the queue */ if(is_array($_SESSION['messages'])) { foreach($_SESSION['messages'] as $m) echo $m; @@ -428,6 +408,15 @@ function display_messages() $_SESSION['messages'] = array(); } +function upTree($id, &$navTree) { + $q=mysql_query("SELECT * FROM rolestasks WHERE id='$id'"); + $r=mysql_fetch_assoc($q); + $navTree[]=$r; + if($r['pid']>0) { + upTree($r['pid'], &$navTree); + } +} + $HEADER_SENT=false; function send_header($title="", $nav=null, $icon=null, $titletranslated=false) { @@ -731,6 +720,24 @@ if($_SESSION['nav']['secondary']) { echo "\n"; } + +//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)."'"); +if($r=mysql_fetch_object($q)) { + //okay we found it, now what do we do? + //FIXME: we need to populate the secondarynva, tertiarynav, and select the right thing in the accordion, + //because we cannot assume that the user navigated to this page via the pri/sec/ter nav menus + $navTree=array(); + upTree($r->id,&$navTree); + foreach($navTree AS $t) { + print_r($t); + echo "
"; + } + +} + + ?> "; $cl="";