Hello everyone,
Thanks a lot for your all replies, I do want to post all the coding which are require or include for you, but I'm wondering that my php pages are quite long, I hope you guys can understand all.
Please let me know if there is anything wrong. Sorry I didn't comment much in my php code, I should do that but sorry i am too busy. If you need any futher information, let me know pls.
Thanks a lot again
"The main problem occurs in menu_manager.php file, I think"
Quyen,
file content.php:
<div class="page-wrapper">
<?php
if(!isset($_SESSION['user_id'])){
header("location: alert_box.php?opt=no_permission");
}
else{
if(isset($_GET["content"])){
$content = $_GET["content"];
switch($content){
case "home":
break;
case "menus":
require_once("menu_manager.php");
break;
case "users":
require_once("user_manager.php");
break;
case "portfolio":
break;
case "cart":
break;
}
}
}
?>
</div>
file menu_manager.php:
<?php
$query = "SELECT * FROM menu
ORDER BY last_edit DESC";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
if($cnt_records){
$per_page = 10;
$start = 0;
$num_of_page = ceil($cnt_records/$per_page);
if(isset($_GET['page'])){
$get_request = $_GET['page'];
if($get_request!="")
{
$start = ($get_request-1) * $per_page;
}
else
{
$start = 0;
}
}
else{
}
?>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<div class="sub-menuitems">
<form name="formPaging" id="formPaging" action="index.php?content=menus" method="post">
<?php
if($num_of_page >=2){
?>
<div class="items">
Page:
<select name="page" id="page" onchange="document.formPaging.submit()">
<option selected="selected">Select one</option>
<?php
for($index=1;$index <= $num_of_page;$index++)
{
if($get_request == $index)
{
echo "<option value=$index>$index </font>";
}
else
{
echo "<option value=$index>$index </font>";
}
}
?>
</select>
<?php
if(isset($_POST['page'])){
$selected = $_POST['page'];
for($index=1;$index <= $num_of_page;$index++)
{
if($get_request == $selected)
{
header("location: index.php?content=menus&page=$selected");
}
else
{
header("location: index.php?content=menus&page=$selected");
}
}
}
?>
</div>
<?php
}
?>
</form>
<form name="formMenuitemQuickLaunch" id="formMenuitemQuickLaunch" action="index.php?content=menus&act=item" method="post">
<div class="items">
Item:
<select name="menu_id" id="menu_id" onchange="document.formMenuitemQuickLaunch.submit();">
<option>Select one</option>
<?php
if($cnt_records){
while($row = mysql_fetch_array($result)){
?>
<option value="<?php print $row['menu_id'];?>">
<?php
print $row['name']."--";
if($row['type']==0){print "B";}else{print "F";}
?>
</option>
<?php
}
}
?>
</select>
</div>
</form>
<form name="formMenuGroup" id="formMenuGroup" action="index.php?content=menus&page=1" method="post">
<div class="items">
Quick launch:
<select name="menuType" id="menuType" onchange="document.formMenuGroup.submit();">
<option value="none">Select one</option>
<option value="all">All</option>
<option value="backend">Back-End</option>
<option value="frontend">Front-End</option>
<option value="published">Published</option>
<option value="unpublished">Un-Published</option>
</select>
</div>
</form>
</div>
<div class="sub-menuitems">
<div class="items">
<a href="#">Delete</a>
</div>
<div class="items">
<a href="#">Published</a>
</div>
<div class="items">
<a href="#">None</a>
</div>
<div class="items">
<a href="#" onclick="">Select All</a>
</div>
<div class="items">
<a href="index.php?content=menus&act=formAdd">Add</a>
</div>
</div>
<?php
if(!isset($_GET['act'])){
require_once("menu_content.php");
}
else{
$action = $_GET['act'];
switch($action){
case"item":
if(isset($_POST['menu_id'])){
$menu_id = $_POST['menu_id'];
$query = "SELECT * FROM menu
WHERE menu_id = '$menu_id'
";
$result_items = mysql_query($query);
$cnt_records = mysql_num_rows($result_items);
if($cnt_records){
?>
<div class="sub-content">
<table>
<tr class="col-title">
<td>ID</td>
<td>Group</td>
<td>Name</td>
<td>Link name </td>
<td>Ordering</td>
<td>Published</td>
<td>Details</td>
<td>Edit</td>
<td>Delete</td>
<td>#</td>
</tr>
<?php
while($row = mysql_fetch_array($result_items)){
require("menu_list.php");
}
?>
</table>
</div>
<?php
}
}
break;
case "pos":
if(isset($_POST['pos'])){
$ordering= $_POST['pos'];
$menu_id = $_POST['menu_id'];
$last_edit = date("F j, Y, g:i a");
$query = "UPDATE menu
SET ordering = '$ordering',last_edit = '$last_edit'
WHERE menu_id = '$menu_id'
";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
if($result){
header("location: index.php?content=menus");
}
}
break;
case 'formAdd':
require_once("menu_adding_form.php");
break;
case 'add':
$type = $_POST['type'];
$name = $_POST['name'];
$link_to = $_POST['link_to'];
$ordering = $_POST['ordering'];
$created_date = date("F j, Y, g:i a");
$last_edit = date("F j, Y, g:i a");
if(isset($_POST['published'])){
$status = 1;
}
else{
$status = 0;
}
if($name == ""){
header("location: alert_box.php?opt=empty");
}
else{
$table = "menu";
$cols = "menu_id,type,name,link_to,ordering,
status,created_date,last_edit
";
$values = "'','$type','$name','$link_to','$ordering',
'$status','$created_date','$last_edit'
";
$query = "INSERT INTO menu ($cols)
VALUES ($values)
";
$result = mysql_query($query);
if($result){
header("location: index.php?content=menus");
}
else{
header("location: alert_box.php?opt=not_insert");
}
}
break;
case "more":
if(isset($_GET['id'])){
$menu_id = $_GET['id'];
$query = "SELECT * FROM menu
WHERE menu_id = '$menu_id'
";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
if($cnt_records > 0){
require("menu_editing_form.php");
}
}
break;
case "edit":
$menu_id = $_POST['menu_id'];
$type = $_POST['type'];
$name = $_POST['name'];
$link_to = $_POST['link_to'];
$ordering = $_POST['ordering'];
$last_edit = date("F j, Y, g:i a");
if(isset($_POST['published'])){
$status = 1;
}
else{
$status = 0;
}
if($name == ""){
header("location: alert_box.php?opt=empty");
}
else{
$set = "type = '$type',
name = '$name',
link_to = '$link_to',
ordering = '$ordering',
status = '$status',
last_edit = '$last_edit' ";
$query = "
UPDATE menu
SET $set
WHERE menu_id = '$menu_id'
";
$result = mysql_query($query);
if($result){
header("location: index.php?content=menus");
}
else{
header("location: alert_box.php?opt=not_updated");
}
}
break;
case "delete":
if(!isset($_GET['id'])){}
else{
$menu_id = $_GET['id'];
$query = "DELETE FROM menu
WHERE menu_id = '$menu_id';
";
$result = mysql_query($query);
if($result){
header("index.php?content=menus");
}
else{
print mysql_error();
header("alert_box.php?opt=delete_error");
}
}
break;
case "status":
if(isset($_GET['id']) && isset($_GET['cur'])){
$menu_id = $_GET['id'];
$last_edit = date("F j, Y, g:i a");
$current_status = $_GET['cur'];
if($current_status == 0){
$status = 1;
}
elseif($current_status == 1){
$status = 0;
}
else{
header("location: alert_box.php?opt=no_permission");
}
$query = "UPDATE menu
SET status = '$status', last_edit = '$last_edit'
WHERE menu_id = $menu_id
";
$result = mysql_query($query);
if($result){
header("location: index.php?content=menus&page=1");
}
else{
header("location: alert_box.php?opt=not_updated");
}
}
break;
}
}
}
?>
Required files:
menu_list.php
<tr>
<td>
<?php print $row['menu_id']?>
</td>
<td>
<?php
if($row['type'] == 1){
print "Front-end";
}
else{
print "Back-end";
}
?>
</td>
<td>
<?php print $row['name'];?>
</td>
<td>
<?php print $row['link_to'];?>
</td>
<form name="orderingForm" id="orderingForm" action="index.php?content=menus&act=pos&page=1" method="post">
<td>
<?php
print $row['ordering'];
$current_id = $row['menu_id'];
?>
<input type="hidden" name="menu_id" id="menu_id" value="<?php print $current_id;?>" />
<?php
if(!isset($_GET['act'])){
}
else{
?>
<select name="pos" id="pos" onchange="submitFormOrdering()">
<option selected="selected">Select</option>
<?php
$query = "SELECT * FROM menu";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
for($i= 1; $i<= $cnt_records; $i++){
?>
<option><?php print $i;?></option>
<?php
}
?>
</select>
<?php
}
?>
</td>
</form>
<td>
<?php
if($row['status'] == 1){
print "<a href='index.php?content=menus&act=status&id="; print $row['menu_id']."&cur="; print $row['status']."'><font color='#FF3300'>Yes</font> </a>";
}
else{
print "<a href='index.php?content=menus&act=status&id="; print $row['menu_id']."&cur="; print $row['status']."'><font color='#006600'> No </font> </a>";
}
?>
</td>
<td>
<a href="index.php?content=menus&act=more&id=<?php print $row['menu_id'];?>">Detail</a>
</td>
<td>
<a href="index.php?content=menus&act=more&id=<?php print $row['menu_id'];?>">Edit</a>
</td>
<td>
<a href="index.php?content=menus&act=delete&id=<?php print $row['menu_id'];?>">Delete</a>
</td>
<td>
<form name="multiSelectedForm" id="multiSelectedForm">
<input type="checkbox" name="selectedItems" id="selectedItems" />
</form>
</td>
</tr>
menu_adding_form.php
<link href="css/style.css" rel="stylesheet" type="text/css" />
<div class="sub-content">
<table>
<tr class="form-title">
<td colspan="2">Add a new menuitem</td>
</tr>
<form name="menuAddingForm" id="menuAddingForm" method="post" action="index.php?content=menus&act=add">
<tr>
<td class="comp-title">Group of menu </td>
<td>
<select name="type" id="type">
<option value="1">Front-End</option>
<option value="0">Back-End</option>
</select>
</td>
</tr>
<tr>
<td class="comp-title">Menuitem name</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td class="comp-title">Link to</td>
<td>
<select name="link_to" id="link_to">
<option value="home">Home page</option>
<option value="aboutus">About Us</option>
<option value="webdesigns">Web Designs</option>
<option value="webtemplates">Web Templates</option>
<option value="contact">Contact Us</option>
<option value="cart">Shopping Cart</option>
<option value="menus">Menus</option>
<option value="users">Users</option>
</select>
</td>
</tr>
<tr>
<td class="comp-title">Ordering</td>
<td>
<select name="ordering" id="ordering">
<?php
$query = "SELECT * FROM menu";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
for($i= 1; $i<= $cnt_records; $i++){
print '<option>'.$i.'</option>';
}
?>
<option><?php print $cnt_records + 1?></option>
</select>
</td>
</tr>
<tr>
<td class="comp-title">Published</td>
<td>
<input type="checkbox" name="published" id="published"/>
</td>
</tr>
<tr>
<td class="comp-title"> Enter or click
</td>
<td>
<input type="submit" value="Save this record"/>
<input type="reset" name="reset" value="Reset"/>
<input type="reset" name="cancel" value="Cancel" onClick="javascript: history.go(-1);"/>
</td>
</tr>
</form>
</table>
</div>
menu_editing_form.php
<div class="sub-content">
<table>
<tr class="form-title">
<td colspan="2">Detail of menuitems <font color="#CC3300"> " <?php print $menu_id; ?> "</font></td>
</tr>
<form name="menuEditingForm" id="menuEditingForm" method="post" action="index.php?content=menus&act=edit">
<tr>
<td class="comp-title">Group of menu </td>
<td>
<select name="type" id="type">
<?php
while($row = mysql_fetch_array($result)){
?>
<option value="<?php print $row['type'];?>" selected>
<?php
$menu_id = $row['menu_id'];
$type = $row['type'];
$name = $row['name'];
$link_to = $row['link_to'];
$status = $row['status'];
$ordering = $row['ordering'];
$created_date = $row['created_date'];
$last_edit = $row['last_edit'];
if($type == 0){
print "Back-End";
}
else{
print "Front-End";
}
?>
</option>
<?php
}
if($type == 0){
?>
<option value="1" >Front-End</option>
<?php
}
else{
?>
<option value="0" >Back-End</option>
<?php
}
?>
</select>
<input type="hidden" name="menu_id" id="menu_id" value="<?php print $menu_id; ?>">
</td>
</tr>
<tr>
<td class="comp-title">Menuitem name</td>
<td><input type="text" name="name" id="name" value="<?php print $name; ?>"/></td>
</tr>
<tr>
<td class="comp-title">Link to</td>
<td>
<select name="link_to" id="link_to">
<option value="<?php print $link_to;?>" selected><?php print $link_to;?></option>
<?php
$query = "SELECT * FROM menu
WHERE link_to <> '$link_to'
ORDER BY ordering ASC
";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
if($cnt_records){
while($row = mysql_fetch_array($result)){
$type = $row['type'];
?>
<option value="<?php print $row['link_to'];?>">
<?php
print $row['link_to']."--";
if($type == 0){
print "Back";
}
else{
print "Front";
}
?>
</option>
<?php
}
}
?>
</select>
</td>
</tr>
<tr>
<td class="comp-title">Ordering</td>
<td>
<select name="ordering" id="ordering">
<?php
$query = "SELECT * FROM menu";
$result = mysql_query($query);
$cnt_records = mysql_num_rows($result);
for($i= 1; $i<= $cnt_records; $i++){
$start = $i + 1;
?>
<option <?php if($ordering == $i){?>selected="selected" <?php }?>>
<?php print $i;?>
</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td class="comp-title">Published</td>
<td>
<input type="checkbox" name="published" id="published" <?php if ($status == true){ ?>checked<?php } ?> />
</td>
</tr>
<tr>
<td class="comp-title">Created on </td>
<td>
<label><?php print $created_date; ?></label>
</td>
</tr>
<tr>
<td class="comp-title">Last edited</td>
<td>
<label><?php print $last_edit ; ?></label>
</td>
</tr>
<tr>
<td class="comp-title"> Enter or click
</td>
<td>
<input type="submit" value="Save this record"/>
<input type="reset" name="reset" value="Reset"/>
<input type="reset" name="cancel" value="Cancel" onClick="javascript: history.go(-1);"/>
</td>
</tr>
</form>
</table>
</div>
Last edited by quyen (2009-11-13 00:36:27)