ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have some files I am trying to get to communicate with my main file default.php. So what have is menu.css (takes care of my sidebar), menu.htm (contains JS for all the submnmenus and such), topmenu.htm (has JS for the top menu), and footer.htm (same as the other 2 but obviously footer) , default.css (takes care of all other css info). So what I am trying to do is call the .html files from default.php so that I don't have a .html file with all this excess JS everywhere. so here is what I have in default.php
Code:
//this is the very top lines//
<?php include("menu.htm"); ?>
<?php include("topmenu.htm"); ?>
<?php include("footer.htm");?>
//html stuff that was prexisting
<?php topmenu(); ?>
//this is placed where I want the menu followed by content//
<?php menu(); ?> //located where that menu goes
<?php footer();?> //located at the bottom where the footer goes
I have used this technique calling a .php script to a .php file. but I am not sure if it works the same way.
If it does not work, you can do the following
rename topmenu.htm to topmenu.php; if your server parses htm files as php, this step is not necessary but I consider it neater.
edit topmenu.php
Code:
<?php
function topmenu() {
?>
your original html content here
<?php
}
?>
The first three lines open a function called topmenu and the last three lines close the function. The content in between is treated as html.
You can now include topmenu.php in your other php files and call topmenu(). Repeat this step for the other files.
Still nothing, do I need to remove the <html> tags at the beginning and the end of the menu.php, topmenu.php, footer.php? Also do I still include them like did above in default.html?
and lastly should I do anything special with the JS inside what I just made into a .php script? or are the included html tags surrounding them work just fine?
<?php
include("../inc/menu.inc.php");
function do_htmlheader($title="")
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<?php
echo "<head>\n";
if(isset($_SESSION['db']))
{
$db=strtoupper($_SESSION['db']);
echo "<title>Incident Logging System - $db - $title</title>\n";
}
else
echo "<title>Incident Logging System - $title</title>\n";
echo "<link rel=\"stylesheet\" href=\"btd2.css\" type=\"text/css\">\n";
echo "<link rel=\"stylesheet\" href=\"menu.css\" type=\"text/css\">\n";
?>
<script language="javascript" type="text/javascript" src="datetimepicker.js"></script>
<script type="text/javascript">
<!--
window.onload=montre;
/******************/
/* show a submenu */
/******************/
function montre(id)
{
var d = document.getElementById(id);
// hide submenus
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
if (d) {
d.style.display='block';
}
else
{
}
}
//-->
</script>
<?php
echo "</head>\n";
// we add a montre (show) here to remove open menus when a user clicks on another element
echo "<body>\n";
echo "<div id=\"menu\">\n";
display_menu();
echo "</div>\n";
// if one puts the onclick event in the body, the context menu for the submenus does not work with the mouse
// it confused me as a user and will definitely confuse other users
echo "<div id=\"site\" onclick=\"javascript:montre();\">\n";
if(isset($_SESSION['db']))
{
$db=strtoupper($_SESSION['db']);
echo "<h1>Incident Logging System ($db)<hr />$title</h1>\n";
}
else
{
echo "<h1>Incident Logging System<hr />$title</h1>\n";
}
}
function do_htmlfooter()
{
echo "</div>\n";
echo "</body>\n";
echo "</html>\n";
}
?>
The function display_menu() is defined in menu.inc.php
Code:
<?php
function display_menu()
{
// menu taken from
// http://tutorials.alsacreations.com/modelesmenus/hd1.htm
// http://tutorials.alsacreations.com/modelesmenus/hd2.htm
// slightly modified (css and added onfocus) and converted to php
?>
I don't escape from php as the menu content dependfs on the login of the user
<?php
}
?>
I include page.inc.php in every page that I have
Code:
<?php
include ("../inc/page.inc.php");
do_htmlheader("Incident Overview");
// other PHP code specific for the page
do_htmlfooter();
?>
Hope this helps enough. And check your server logs to see where it goes wrong.
ok so I have everything KINDA working, the site finds all the image stuff I need. Now my question is how to get the Java Script working for the menu's submenus. I have tried including the exported .htm and what I just converted to .php The only issue is in the side menu not showing the submenu on mouseover like it does if I just run that HTML. I have the pages included correctly cause all of the images are called with the .htm and .php pages that I mentioned above. it is just not using the javascript.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.