PHP - Navigation - How Can I Get The Id Of An Active Tab
hello
navigation - how can i get the id of an active tab i have a top nav which is pulling its tabs from a database how can i get the id of the active tab then pass it in a global to side navigation this is the top nav code Code: [Select] <?PHP require_once("../includes/initialize.php"); global $topNavs; global $pageName; ?> <div id="navWrapper"> <?PHP $topNav = navL1::find_all(); ?> <div id="ddtabs3" class="solidblockmenu"> <ul> <?PHP foreach($topNav as $topNavs): ?> <li><a <?PHP echo ($pageName == $topNavs->title ? 'class="selected"' : '')?> href="<?PHP echo $topNavs->title; ?>.php" id="<?PHP echo $topNavs->title; ?>"><?PHP echo $topNavs->title; echo $topNavs->id;?></a></li> <?PHP endforeach; ?> </ul> </div><!-- #ddtabs3--> </div><!-- #navWrapper--> this prints the id of 5 which is the last tab in my database. if i have tab 1 active how can i get my loop to get that id ? thanks rick Similar TutorialsCode: [Select] <div id="nav"> <ul> <li class="item"><a href="/">Home</a>/</li> <li class="item"><a href="/one">one</a></li> <li class="item"><a href="/two>two</a></li> <li class="item"><a href="/three">three</a></li> </ul> <div> i want to add class='active' to the a tags . when the menu is the current page. namely.when i on the home page. the a label is Code: [Select] <li class="item"><a href="/" class="active">Home</a>/</li> .but the others a label are not have class="active". when i on the one page. it is is Code: [Select] <li class="item"><a href="one" class="active">one</a>/</li>.the others a label are not have class="active". I have got a code working to generate a menu from a mysql table, but I wan't to know if it is possible to have the background colour change to a third option when active. I have 1 background colour for 'off', one for mouseover, but can't figure out how to tell it what they current page is so that it will use a different css class value, as the page obviously reloads after the link is clicked. Is it possible (hope my explanation makes some sence!) My code: At the moment mainNav a: and mainNav a:hover work ok but what I want is a mainNav a:active to stay on after the page has loaded Code: [Select] <?php //function to nest the menu tree function nest_child(&$nodes, $current) { if (!isset($nodes) || count($nodes) < 1) { return; } foreach ($nodes as $id => $item) { if ($current['parentdocid'] == $id) { if (!isset($item['children'])) { $item['children'] = array(); } array_push($item['children'], $current); $nodes[$id] = $item; } else { nest_child($item['children'], $current); } } } //functions to display the tree and expand as appropriate function menu_display($nodes, $display_id) { if (!isset($display_id) || ($display_id == '')) { $display_id = 1; } $result = node_display( array( 'doc_id' => 1, 'children' => $nodes ), $display_id ); return $result[1]; } function node_display($node, $display_id) { global $ROOT; $found = false; $text = ''; if (isset($node[children])) { foreach ($node[children] as $id => $child) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$child[doc_id]'>$child[doc_name]</a>"; $result = node_display($child, $display_id); if ($result[0]) { $found = true; $text .= "<ol>$result[1]</ol>"; } if ($child[doc_id] == $display_id) { $found = true; if (isset($child[children])) { $text .= "<ol>"; foreach ($child[children] as $id => $grandchild) { $text .= "<li class='mainNav'><a href='$ROOT/index.php?doc_id=$grandchild[doc_id]'>$grandchild[doc_name]</a>"; } $text .= "</ol>"; } } $text .= "</li>"; } } if ((!$found) && ($display_id != 1)) { $text = ''; } return array($found, $text); } ?> <ul class="menu"> <?php //retrieve all the menu elements $result = mysql_query('SELECT * FROM docs ORDER BY doc_order ASC'); $menu = array(); while ($row = mysql_fetch_assoc($result)) { $menu[$row['doc_id']] = $row; } //nest the elements foreach ($menu as $id => $item) { if ($item['parentdocid'] != 1) { nest_child($menu, $item); unset($menu[$id]); } } //display the tree print menu_display($menu, $doc_id); ?> </ul> Hi, I am am looking to develop further the code below. This code allows me to display a left navigation bar with Main Links and then if you click a Main link, that link is listed first in the list and its' submenu appears below. For the majority of links in the navigation bar this is fine. But for about 2 of the Main links this basic navigation is not suitable. I need the navigation for 2 of the links to offer more depth. So, for example, if you click Accessories in: Shoes Trousers Shirts Accessories Looks like this if Accessories is clicked: Accessories Belts Cuff Links Wallets Shoes Trousers Shirts Looks like this if belts is clicked (Main link name changed and submenu changed): Accessories - Belts Brown leather Black Leather Multicolour Designs All casual All formal Shoes Trousers Shirts Looks like this is Brown Leather is clicked: Brown Leather Belts Armani Brown Leather Belt 32" Armani Brown Leather Belt 34" Hugo Boss Brown Leather Belt 32" Hugo Boss Brown Leather Belt 34" Shoes Trousers Shirts Currently the code does not allow for this depth in the navigation bar. Any ideas how it could be done? Do I need additional tables for each subcategory. How do I ensure the category clicked does not appear in the rest of the navigation bar, as in the code I have at the moment? Currently the code is: $res = mysql_query("SELECT * FROM categories"); while($row = mysql_fetch_array($res)) { $cats[$row['categoryid']] = $row['categoryname']; } if(isset($_GET['category'])) { $selcat = $_GET['category']; } if(isset($_GET['product'])) { $prod_info = mysql_fetch_array(mysql_query("SELECT * FROM products WHERE productid = ".$_GET['product'])); //Prod_Info now gets stored for use in the main display. $selcat = $prod_info['categoryid']; } if(isset($selcat)) { echo "<a href='categorylist.php?category=".$selcat."'>".$cats[$selcat]."</a>"; unset($cats[$selcat]); //Gets rid of it for later. $res = mysql_query("SELECT productid,name FROM products WHERE categoryid = ".$selcat); while($row = mysql_fetch_array($res)) { echo "<a href='product.php?product=".$row['productid']."'>".$row['name']."</a>"; } } foreach($cats AS $key => $cat) { echo "<a href='categoryview.php?category=".$key."'>".$cat."</a>"; } Thank you for looking at this post, Matt. Hello guys, before I start I'm a relativity new user of PHP so this really could be something extremely simple, I just can't seem to find it, Basically on my website i have php login script, when you're logged on every page you visit checks a file called auth.php, This will tell create a session called, "$SESSION" Inventive i know... That will tell the browser if the user is logged in or not, so it can decide whether or not to create a Login button, or a Log out button, Here's the code i have so far. if ( $SESSION == '' ) { echo "<a href='logout.php" ."Log out"; } else { echo "<a href='login-form.php" ."Log in"; } Now, I believe i'm on the right lines? But i'm not fully sure how to basically in English say, If that session is working or exists, Then do this, if not, do this. I mention again, I'm very new to PHP so any help would be very appreciated! I added <?php $_menu = ''?> <?php foreach ($this->getStoreCategories() as $_category): ?> <?php $_menu .= $this->drawItem($_category) ?> <?php endforeach ?> <?php if ($_menu): ?> <div class="nav-container"> <ul id="nav"> <li class="level0 first nav-home"><a href="<?php echo $this->getUrl() ?>"><span><?php echo $this->__('Home') ?></span></a></li> <?php echo $_menu; ?> <li class="level0 nav-1 parent"><a href="<?php echo $this->getUrl('contacts')?>"><span><?php echo $this->__('Contact') ?></span></a></li> <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('menu')->toHtml() ?> </ul> </div> <?php endif; ?> to top.phtml and it works as expected, I now have CMS links in my nav but how can I make them have active state like the category links do?? here is the site: http://pro-tools-training.com/new-magento/index.php/video-1.html I have a database with Users as a table. It has the normal stuff, id, username, password, and I have anther in it called lastactive. It is DATETIME, and I am wondering how I would make a sql query select the users in the database 'users' and see who has been active in the past 15 mins. What I am asking is how I could do this, and would it be better to use a different structure other then DATETIME. Hi... I am pretty new to ldap and active directory I am creating a site and want to use Active Directory users as the login to the site. This would be the best way to allow everyone to the site and keep the users and passwords up to date. How do you use PHP to talk with Active Directory to do this login? I have read things about LDAP. Do you have to have that? If so, how do you get that to work? and how to configure ldap and where to configure ldap is it server or in my local system. Please give me an idea how to configure n how to integrate active directory Gah, can anyone help. We've written a web app, it was all tested and doing what it should and at the eleventh hour I've hit a snag. We use TCDPF to create printed reports from a MySQL database. It does what it should when accessed over the 'net however I've just been informed that their firewall won't allow Activ X content through and they won't (as opposed to can't) create an exception to trust our site. So, I need a workaround. Option 1) Host a complete copy on their internal network (exceptionally undesirable as it becomes unmanageable). Option 2) Split the printing components out and host that on a web server on their internal network. Option 3) Find another way of producing PDF output from a MySQL web app that can traverse a strict firewall. My preference is for option 2, but I'd like some opinions/thoughts on the best way to proceed before I code myself into a corner once more Thus far I've tried using an include to a different server but it is spitting it's dummy at the moment. Does anyone have any opinions on the *easiest* way to work around the problem? Thanks, Rob Sorry if i posted this in the wrong place but i dident see anthing about Active Directory or Security Questions
But has anyone used Active Directory as their User Database? Has anyone even tryed braking Active Directory with injection attacks?
Notes that i have found so far:
Php Sends to CMD first so encode userdata in base64 as a transport layer
$rand is a random number to prevent users from useing Success: as a ligitimate user
You will need to clean up the many many spaces that powershell sends back as it is a concole
Special Charicters dont need to be escaped
I am using
Win 2008 RC2
Apache
PHP (of course)
Powershell
Active Directory
PHP Script
$psScriptPath = 'C:/Apache/PSScripts/' //Path outside Website Root $rand = mt_rand(mt_getrandmax(),mt_getrandmax()); //UTF-8 Standard only $username = utf8_decode($_POST["username"]); $password = utf8_decode($_POST["password"]); $base64_username = base64_encode($username); //Transport Layer Base64 $base64_password = base64_encode($password); //Transport Layer Base64 //The danger happens here as it is sent to powershell. $query = shell_exec('powershell.exe -ExecutionPolicy ByPass -command "' . $psScriptPath . '" < NUL -rand "' . $rand . '" < NUL -base64_username "' . $base64_username . '" < NUL -base64_password "' . $base64_password . '" < NUL');// Execute the PowerShell script, passing the parametersPowershell Script #*============================================================================= #* Script Name: adpwchange2014.ps1 #* Created: 2014-10-07 #* Author: #* Purpose: This is a simple script that queries AD users. #* Reference Website: http://theboywonder.co.uk/2012/07/29/executing-powershell-using-php-and-iis/ #* #*============================================================================= #*============================================================================= #* PARAMETER DECLARATION #*============================================================================= param( [string]$base64_username, [string]$base64_password, [string]$rand ) #*============================================================================= #* IMPORT LIBRARIES #*============================================================================= if ((Get-Module | where {$_.Name -match "ActiveDirectory"}) -eq $null){ #Loading module Write-Host "Loading module AcitveDirectory..." Import-Module ActiveDirectory }else{ write-output "Error: Please install ActiveDirectory Module" EXIT NUL Stop-Process -processname powershell* } #*============================================================================= #* PARAMETERS #*============================================================================= $username = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64_username)) $password = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($base64_password)) #*============================================================================= #* INITIALISE VARIABLES #*============================================================================= # Increase buffer width/height to avoid PowerShell from wrapping the text before # sending it back to PHP (this results in weird spaces). $pshost = Get-Host $pswindow = $pshost.ui.rawui $newsize = $pswindow.buffersize $newsize.height = 1000 $newsize.width = 300 $pswindow.buffersize = $newsize #*============================================================================= #* EXCEPTION HANDLER #*============================================================================= #*============================================================================= #* FUNCTION LISTINGS #*============================================================================= Function Test-ADAuthentication { Param($Auth_User, $Auth_Pass) Write-Output "Running Function Test-ADAuthenication" $domain = $env:USERDOMAIN Add-Type -AssemblyName System.DirectoryServices.AccountManagement $ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain $pc = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($ct, $domain) $pc.ValidateCredentials($Auth_User, $Auth_Pass).ToString() } #*============================================================================= #* SCRIPT BODY #*============================================================================= Write-Output $PSVersionTable Write-Output " " $authentication = Test-ADAuthentication "$username" "$password" if ($authentication -eq $TRUE) { Write-Output "Success:$rand Authentication" }elseif ($authentication -eq $FALSE) { Write-Output "Failed:$rand Authentication" }else { Write-Output "Error: EOS" EXIT NUL Stop-Process -processname powershell* } #*============================================================================= #* SCRIPT Exit #*============================================================================= Write-Output "End Of Script" EXIT NUL Stop-Process -processname powershell* Morning(at least for me anyway) All, I am currently integrating a facebook/style chat system into my webpage. I am going to build the active user list myself but need a little guidance on how to list my users which are online and how to detect when the have gone. When my users login i store only their userid in a session like many login systems. When they login i could simply add their name to a active_users table, but how would i detect whether they are still alive? Any help would be great. Thanks Sam Hi All, How would I go about programming a HTML button that cannot be clicked on for two seconds after it loads? As part of a game I wish to stop people simply re-clicking the button and I think a delay of about two seconds would stop abuse of this (if they click it every two seconds then that's fine). I have read the manual for sleep() but it doesn't do exactly what I want - I want the rest of the page to load (and display), and the button to be grayed out for the two seconds, and then the button to be active. James Hello, I'm working on a Class with my CMS and can't get it to work properly. It is the textClass of my cms. You can add and delete text on the website but I want to add an active or non active option. This is de code I got now but it isnt working and I cant find te problem. The radio button in my cms wich shows active or non active works fine and when i change it to non active it changes in the database to 0 so the problem isnt there I think. Can anybody help me out? Tnx:) Code: [Select] public function getTeksten($database, $taal, $actief = NULL, $bladzijde = NULL, $id = NULL) { $sql = "SELECT * FROM ".$database."_teksten WHERE tekst_taal=:taal"; if(!empty($id)) { if(is_numeric($id)) { $sql .= " AND tekst_ID=:id"; } if(!empty($actief) && $actief == 1) { $sql .= " WHERE tekst_actief='1'"; } } else if(!empty($bladzijde)) { if(is_numeric($bladzijde)) { $sql .= " AND tekst_bladzijde=:bladzijde"; } else { return NULL; } } $sql .= " ORDER BY tekst_volgorde ASC"; try { $stmt = $this->db->prepare($sql); $stmt->bindParam(":taal", $taal, PDO::PARAM_STR); if(!empty($id) && is_numeric($id)) { $stmt->bindParam(":id", $id, PDO::PARAM_INT); } else if(!empty($bladzijde) && is_numeric($bladzijde)) { $stmt->bindParam(":bladzijde", $bladzijde, PDO::PARAM_INT); } $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_OBJ); $stmt->closeCursor(); return $result; } catch(Exception $e) { die($e->getMessage()); } } I have to text items on my homepage and turned one to non active but what happened now is that is show all of my text items on my homepage. Cant find the problem:( Someone that can help me out here? I would like to know how to make my links show that it's active. For example if I click on a link that says overview then that link has to be highlighted. This is the code that I have: Code: [Select] <?php if (isset($this->_params['submenus']) && is_array($this->_params['submenus'])){ foreach ($this->_params['submenus'] as $submenu){ ?> <li class="active"><a href="<?php echo $this->get_uri("/{$submenu['controller']}/{$submenu['action']}") ?>" onclick="javascript:return setSubMenu(<?php echo $submenu['id'] ?>);"><?php echo strtoupper($submenu['name'])?></a></li> <?php } } ?> Unfortunately with this code all the links are selected as active. Trying to make it so people need a active session in order to access the page after the log in page and if they dont then it redirects them back to the log in page. My session works fine. I tested and made sure. it saves the user_id lets me display the page but how do I keep someone from simply going to the webpage with out loging in? Just a simple if statment checking if lastactive is empty or not? is that secure? Code: [Select] <?php include_once("connect.php"); if(isset($_SESSION['user_id'])) { // Login OK, update last active $sql = "UPDATE users SET lastactive=NOW() WHERE id='".mysql_real_escape_string($_SESSION['user_id'])."'"; mysql_query($sql); }else{ header("Location: index.php"); exit(); } ?> hi, i looking for a design report like crystal report or active reports but for php the objective is creat a report using mysql data and save the template and load that report in a pdf file for print or save any one know something like that? i already use classes like class.ezpdf.php but i spend many hours creating complex reports, all is created using a text editor.. thanks for your help I retrieve certain messages from the database that has bbtags inside them. Something similar to this forum: Quote from: admin Contact me at [] test@hotmail.com Quote When i display them in a webpage I need the tags to work accordingly. I do not know how to write a function or do somethin to display them by making the quotes active .. Hi all Good morning I did connect to the Active Dirctroy using PHP Quote $ldapHost = "ldap://XXX.com"; $ldapPort = "389"; $ldapUser ="XXX@XXX.com"; $ldapPswd ="XXX"; $ldapLink =ldap_connect($ldapHost, $ldapPort) or die("Can't establish LDAP connection"); ldap_bind($ldapLink,$ldapUser,$ldapPswd) or die("Can't bind to server."); it's working well but how can I print the username I mean since I'm connected with Active Dirctory I want any user who enter the webpage it will print his name that stored in Active Dirctory thank you I've been browsing the foams for a while now but haven't posted until now. Anyway, I have a table containing a list of items, I want a column to have either a red or a green icon depending on the state I set manually. My question is, how would I best set this up? I'd like to be able to have a simple checkbox admin page that when saved the other page reflects the state either 0 (inactive) or 1 (active), what would be the best way of storing these values and then reading them again? By this I mean a text file, MySQL, etc. I have some knowledge of PHP and MySQL, though not a massive amount. Hi Everyone, I'm semi-new to php and trying to create a site where I have only one includes file for my navigation (main_nav.inc) and 2-3 includes files (main_template.inc) that act as templates. I then call the the nav and the template in my index.php file. Everything was working fine until I decided I should use php have my links appear active depending on which page the user is on. Everything works totally fine if I insert the code for my nav (including both the html and php) into my main_template.inc file but when I make that code into it's own includes file (main_nav.inc), I get an error. I believe the issue is with using both single and double quotes in my code and wrapping that code in single quotes in my main_nav.inc file. Here is the code from my main_nav.inc file: <?php $main_nav = ' <div id="mainNav"><ul id="mainNav"> <li><a href="index.php" <?php if ($page=='index.php') { ?> class="active" <?php } ?>>Welcome</a></li> <li><a href="healthcare.php" <?php if ($page=='healthcare.php') { ?> class="active" <?php } ?>>Healthcare</a></li> </ul></div> '; // end main_nav ?> I think that since the code is wrapped in single quotes, I can only use double quotes in my code. This is the only difference I can figure out between inserting the code into the template directly (which works perfectly fine) and inserting it as a separate inc file. When I use the main_nav.inc file I get the following error: Parse error: syntax error, unexpected T_STRING in /home/content/k/a/l/kalilaks3/html/includes/main_nav.inc on line 11 I tried changing the quotes around ($page=='index.php') to ($page=="index.php") but that causes the browser to literally read the name of the link a class="active">Welcome I also tried variations of escaping quotes such as ($page==\"index.php\") and even escaping the other quotes and wrapping everything in double quotes as opposed to single quotes. Here is my code for my main_template.inc file <?php $page = basename($_SERVER['SCRIPT_NAME']); $page_title = "Welcome"; include_once ("includes/main_nav.inc"); // sets variable include_once ("home_template.inc"); // sets all variables ?> And here is my index.php file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="healthcare" name="keywords"></meta> <meta content="healthcare" name="description"></meta> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title><?php echo $page_title; ?></title> <link rel = "stylesheet" href = "_css/layout.css"></link> <script type="text/javascript" src="scripts/script.js"></script> </head> <body> <div id = "header"><div id = "globalHeader"> <?php echo $main_nav; ?> </div></div> </body> </html> Any help or suggestions would be greatly appreciated!!! I would love to get this figured out so that I only have to create my navigation once for all my sites! Hi all, great forum so far. Am new so hope I find my way around ok. I have been working on a site that uses mysql to store the info and then php to talk to mysql. Basically the site has a custom build CMS (I'm learning). I have created a dynamic subnav in my page where entries can be added or removed in the admin area for the site. Here is the code that pull the info etc. How can I set an active state for nav? Each sub nav link dynamically created the href. I need to find if the url is the same as the href for each subnav link. If it is then add a class called .active to that li item only. Hope that makes sense? any help would be great thank you, Code: [Select] $subnav = new DataConn; //connection to database with my classes file $subnav->query("SELECT * FROM stock_categories ORDER BY category_order"); $currCatID = 0; $currCatTitle = ''; $i = 1; ?> <ul class="subnav"> <?php while($rs_subnav = mysql_fetch_array($subnav->result)) { if ($i == 1) { $currCatID = $rs_subnav['category_id']; $currCatTitle = $rs_subnav['title']; } ?> <li><a href="stock-list.php?cat=<?php echo $rs_subnav['category_id']; ?>"><?php echo $rs_subnav['title']; ?></a></li> <?php $i++; } ?> </ul> |