<?php
$dbserver='localhost';
$dbuser='root';
$dbpwd='';
$dbase='mymenugen';
$link = mysql_connect ($dbserver, $dbuser, $dbpwd) or die ("Could not connect");
mysql_select_db($dbase);
include("classes/mymenugen_class.php"); // include myMenuGen class
$myMenu = new myMenuObject;
if(isset($_REQUEST['saveNew'])){
$myMenu->saveHomePage($_POST['homepage']);
$menu_id = array();
for($j = 1; $j <= $_POST['iterations']; $j++) {
$menu_id[] = $_POST['menu_id'.$j];
}
$tmpArray = $myMenu->getPages();
$myMenu->deleteRemovedMenuItems($menu_id); // Remove any existing items before saving them again
for($j = 1; $j <= $_POST['iterations']; $j++) {
$myMenu->position = $j;
$myMenu->menu_title = htmlentities($_POST['menu_title'.$j], ENT_QUOTES);
$myMenu->menu_id = $_POST['menu_id'.$j];
$myMenu->parent_id = $_POST['parent_id'.$j];
$myMenu->menu_image = $_POST['menu_image'.$j];
foreach($tmpArray as $val) {
$myMenu->getPage($val);
if($_POST['page_inp'.$j] == $myMenu->page_link) {
$myMenu->page_id = $_POST['page_sel'.$j];
break;
} else {
$myMenu->page_id = '';
}
}
if(empty($myMenu->page_id)) {
$myMenu->external_link = $_POST['page_inp'.$j];
} else {
$myMenu->external_link = '';
}
if(isset($_POST['menu_hr'.$j])) { $myMenu->menu_hr = 'yes'; }
else { $myMenu->menu_hr = 'no'; }
if($myMenu->itemExists($myMenu->menu_id) && !empty($myMenu->menu_id)) {
$myMenu->updateMenuItem($myMenu->menu_id);
} else {
$myMenu->saveMenuItem();
}
}
}
if(count($myMenu->getMenuItemsID()) > 0) { $myMenu->new_record = false; }
$tmpString = '<script type="text/javascript">
//<![CDATA[
<!--
// Find the homepage
var S_homepage = "";
var S_homepage_link = "";';
// Collect the homepage identity
$homepage = $myMenu->getHomePage();
$tmpString .= 'S_homepage = "'.$myMenu->page_id.'";'."\n";
$tmpString .= 'S_homepage_link = "'.$myMenu->page_link.'";'."\n";
$tmpString .= 'S_homepage_desc = "'.$myMenu->page_description.'";'."\n";
// Create array pagesList
$tmpString .= ' array_count = 0;
pagesList = new Array();
var myHash = {id:\'\', title:\'\'};
pagesList[array_count++] = myHash;';
// Collect all the pages and put into an array
$tmpArray = $myMenu->getPages();
foreach($tmpArray as $val) {
$myMenu->getPage($val);
$tmpString .= 'var myHash = {id:\''.$myMenu->page_id.'\', title:\''.$myMenu->page_link.'\', description:\''.$myMenu->page_description.'\'};
pagesList[array_count++] = myHash;';
}
// Create array menuList
$tmpString .= ' array_count = 0;
menuList = new Array();
var myHash = {id:\'\', title:\'\'};
menuList[array_count++] = myHash;';
// Collect all the menu items and put into an array
$tmpArray = $myMenu->getMenuItemsOrdered();
foreach($tmpArray as $val) {
$myMenu->getMenuItem($val);
$tmpString .= 'var myHash = {id:\''.$val.'\', title:\''.$myMenu->menu_title.'\'};
menuList[array_count++] = myHash;';
}
// Lookup to generate possible homepage select list and set the current homepage
$tmpString .= ' Array.prototype.lookupPage = function (id) {
identity=document.getElementById(id);
identity.options.length=this.length;
var i;
for (i=0; i < this.length; i++) {
identity.options[i].value = this[i][\'id\'];
identity.options[i].text = this[i][\'title\'];
if(this[i][\'id\'] == '.$homepage.')
identity.options[i].selected = true;
}
}
Array.prototype.lookupArray = function (id) {
identity=document.getElementById(id);
identity.options.length=this.length;
var i;
for (i=0; i < this.length; i++) {
identity.options[i].value = this[i];
identity.options[i].text = this[i];
switch(id) {
case "homepage":
if(this[i] == S_homepage) identity.options[i].selected = true;
break;
}
}
}
function checkPage(id, titleid) {
identity = document.getElementById(id);
target = document.getElementById(titleid);
user_input = identity.options[identity.selectedIndex].value;
if(user_input > 0) {
for (i=0; i < pagesList.length; i++) {
if(pagesList[i][\'id\'] == user_input) {
target.value = pagesList[i][\'description\'];
}
}
} else {
target.value = \'\';
}
}
onload=function() {
checkPage(\'homepage\', \'homepageDesc\');
}
//-->
//]]>
</script>
<form name="form1" method="post" action="'.$_SERVER['PHP_SELF'].'">
<div id="searchLayout">
<table cellspacing="0">
<tr>
<td width="10%"><b>Homepage</b></td>
<td width="20%">
<select tabindex="1" id="homepage" name="homepage" onchange="checkPage(\'homepage\', \'homepageDesc\')" style="width: 200px;"><option></option></select>
<script type="text/javascript">
//<![CDATA[
pagesList.lookupPage(\'homepage\');
//]]>
</script>
</td>
<td align="right"><input id="homepageDesc" name="homepageDesc" type="text" size="60" value="" readonly="readonly"></td>
</tr>
</table>
</div>
<div id="searchLayout">
<table id="tblMenus">
<thead>
<tr class="noPrint" >
<td colspan="12"><h4>Menu Items</h4></td>
</tr>
<tr id="tblMenusHdr">
<td width="4%"><b>Ord</b></td>
<td width="26%"><b>Menu Title</b></td>
<td width="23%"><b>Page Link</b></td>
<td width="23%"><b>Item Parent</b></td>
<td width="20%"><b>Item Image</b></td>
<td width="6%" align="center"><b>Break After</b></td>
<td width="8%" colspan="5" align="right">
<a href="#" onclick="insertRowToTableEnd();" title="Add new item">
<img src="'.$myMenu->rootDir.'images/mymenu/addline.png" class="noPrint" alt="Add new line at the end of the list" height="24px" width="24px" />
</a>
</td>
</tr>
</thead>
<tbody></tbody>
</table>
<p>
<br />
<div style="float: left;"><input type="submit" id="cancel" name="cancel" class="noPrint" value="Cancel" /></div>
<div style="float: right;"><input type="submit" id="saveNew" name="saveNew" class="noPrint" value="Submit" /></div>
<input type="hidden" name="iterations" id="iterations" value="0" />
</p>
</div>
</form>
<script src="classes/mymenugen.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
//<![CDATA[
<!--
';
if($myMenu->new_record) {
$tmpString .= 'fillInRows(1, pagesList, menuList);';
} else {
$tmpString .= 'fillInRows(0, null);';
$tmpArray = $myMenu->getMenuItemsOrdered();
foreach($tmpArray as $val) {
$myMenu->getMenuItem($val);
$tmpString .= 'addRowToTable(null,"'.addslashes(html_entity_decode($myMenu->menu_title, ENT_QUOTES)).'", pagesList, menuList, "'.$myMenu->page_link.'", "'.$myMenu->menu_image.'", "'.$myMenu->menu_hr.'", "'.$myMenu->parent_id.'", "'.$myMenu->page_id.'", "'.$val.'");';
}
}
$tmpString .= ' //-->
//]]>
</script>';
echo '<!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" >
<head>
<title>myMenuGen</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css" title="currentStyle" media="screen">
@import url(style/style.css);
@import url(style/menu.css);
</style>
<!--[if IE 7]>
<style type="text/css" media="screen, tv, projection">
/*<![CDATA[*/
.menu li { height: 1%; }
/*]]>*/
</style>
<![endif]-->
<!--[if lte IE 6]>
<style type="text/css" media="screen, tv, projection">
@import url(style/menu4ie.css);
</style>
<script src="classes/adxmenu.js" type="text/javascript"></script>
<![endif]-->
</head>
<body>';
echo $myMenu->getVersion();
echo '<h2>Example Menu</h2>';
echo '<div id="bcsMenu">';
echo '<ul class="adxm menu">';
echo $myMenu->generateMenuStructure();
echo '</ul>';
echo '</div>';
echo '<h2>Menu Generation Form</h2>';
echo $tmpString;
echo ' </body>
</html>';
?>
|