<?php
include"header.php";
if(empty($_SESSION['UserName'])){
header("Location: login.php");
exit;}
$start=0;
$limit=5;
$page='';
$tbl_name="menu";
$targetpage = "menu.php"; //your file name (the name of this file)
if(isset($_POST['fullname'])){
$term=$_POST['fullname'];}
if(isset($_GET['page'])){
$page=$_GET['page'];
$start=($page-1)*$limit;
}
{
if(isset($_POST['Submit'])){
$query=mysql_query
("select * from $tbl_name where MenuName like '%$_REQUEST[fullname]%' LIMIT $start, $limit");
$search_num_rows = mysql_num_rows($query);
echo "<div class='main'>";
echo"Found " .$search_num_rows. " results for " .$term."</div>";
}
else{
$query=mysql_query("select * from $tbl_name LIMIT $start, $limit");
}
$query_sting = "type=abc";
$url3="$targetpage?".$query_sting;
echo "<div class='main'>";
if(!isset($_GET['Id'])){
if(!isset($_GET['type'])){
echo "<table border='0'>
<tr class='tableheader'>
<th><a href='$url3'>
<img src='images/create.png'>Add New </a></th>
<th>PageName</th>
<th>MenuName</th>
<th>ParentMenuId</th>
<th>LinkWidth</th>
<th>OtherUrl</th>
<th>Status</th>
<th>CreatedDate</th>
<th>OnMainMenu</th>
<th>FooterMenu</th>
<th>Delete</th>
</tr>";
while($row = mysql_fetch_array($query)) {
echo "<tr class='tablerow'>";
$query_sting = "Id={$row['ID']}";
$url1="$targetpage?".$query_sting;
echo "<td><a href='$url1'><img src='images/UPDATE.png'>Edit</a></td>";
$rpId=$row['PageID'];
$result1=mysql_query("SELECT * FROM page WHERE ID=$rpId ");
$row1=mysql_fetch_array($result1);
if ($row['PageID'] == $row1['ID'])
echo "<td>" . $row1['Title'] . "</td>";
else if($row['PageID'] == '0')
echo "<td>Null</td>";
echo "<td>" . $row['MenuName'] . "</td>";
$parentmenuId=$row['ParentMenuID'];
$result2=mysql_query("SELECT * From $tbl_name WHERE ID=$parentmenuId");
$row2=mysql_fetch_array($result2);
if($row['ParentMenuID'] == '0')
echo "<td>Null</td>";
else
echo "<td>" . $row2['MenuName'] . "</td>";
echo "<td>" . $row['LinkWidth'] . "</td>";
if ($row['OtherUrl'] =='')
echo "<td>Null</td>";
else if($row['OtherUrl'] != '0')
echo "<td>" . $row['OtherUrl'] . "</td>";
if($row['Status'] == '1')
echo "<td>active</td>";
else if($row['Status']=='0')
echo "<td>deactive</td>";
echo "<td>" . $row['CreatedDate'] . "</td>";
if($row['OnMainMenu'] == '1')
echo "<td>Yes</td>";
else if($row['OnMainMenu']=='0')
echo "<td>No</td>";
if($row['FooterMenu'] == '1')
echo "<td>Yes</td>";
else if($row['FooterMenu']=='0')
echo "<td>No</td>";
$query_sting = "Id={$row['ID']}";
$url = " menu_delete.php?". $query_sting;
echo "<td><a href='$url' onclick='return checkDelete()'><img src='images/DELETE.png' ></a></td>";
echo "</tr>";
}
echo "</table>";
$rows=mysql_num_rows(mysql_query("select * from $tbl_name"));
$total=ceil($rows/$limit);
echo "<ul class='page'>";
for($i=1;$i<=$total;$i++){
if($i==$page) {
echo "<li class='current'>".$i."</li>"; }
else {
echo "<li><a href='?page=".$i."'>".$i."</a></li>"; }
}
echo "</ul>";
if(isset($_POST['insert'])){
$Number =$_POST['pagination'];
$Number=urlencode($Number);
header ("Location: $targetpage?page=$Number");
if ($Number >= $i || '0'){
header ("Location: $targetpage?page=1");
exit;
}}
echo"<form method='post' id='frm' name='frm' action='menu.php'>
<table width='500' border='0'>
<tr>
<th>Search :</th>
<td><input type='text' name='fullname' id='fullname' /></td>
</tr>
<tr>
<td><input type='submit' name='Submit' value='Search' /></td>
<td> </td>
</tr>
</form>
<form style='width:50%' method='post' id='123' name='1234' action='' >
<tr>
<th>Go To Page:</th>
<td><input type='text' value='' name='pagination' class=''/></td>
</tr>
<tr>
<td><input name='insert' type='submit' class='button' value='go'/></td>
</table>
</form>";
}}}
$PageId=
$MenuName=
$ParentMenuId=
$LinkWidth=
$OtherUrl=
$Status1=
$CreatedDAte=
$FooterMenu=
$OnMainMenu=
$row=
$class=
$LinkWidth="";
if(isset($_GET['Id'])||isset($_GET['type'])){
$Id=$_GET['Id'];
$query = mysql_query("SELECT * FROM menu WHERE ID='$Id'");
$row = mysql_fetch_array($query);
$PageId=$row['PageID'];
$MenuName=$row['MenuName'];
$ParentMenuId=$row['ParentMenuID'];
$LinkWidth=$row['LinkWidth'];
$OtherUrl=$row['OtherUrl'];
$Status1=$row['Status'];
$OnMainMenu=$row['OnMainMenu'];
$FooterMenu=$row['FooterMenu'];
?>
<form style="width:100%" method="post" id="form" >
<table class="viewjob" align="center" ac>
<tr class="tableheader">
<td align="center" colspan="4"> Update </td>
</tr>
<tr class="tablerow">
<td>Page Id</td>
<td><select name='pageID' class="select">
<option value='0' >select any page</option>
<?php
$sql10 = "SELECT ID,Title FROM page";
$val=$PageId?:'';
$rs = mysql_query($sql10) or die(mysql_error());
while($row = mysql_fetch_array($rs)){
$selected = ($val == $row['ID'] ? 'selected="selected"' : '');
echo '<option value ="' . $row['ID'] . '" '. $selected .'>' . $row['Title'] . '</option>';
}
mysql_free_result($rs);
?>
</select></td>
<td>Menu Name</td>
<td><input type="text" value="<?php echo $MenuName;?>" name="menuname" class="inputbox validate[required]"/></td>
</tr>
<tr class="tablerow">
<td>Parent Menu Id</td>
<td><select name='parentmenuID' class="select">
<option value='0' >Non</option>
<?php
if(isset($_GET['Id'])){
$sql9="SELECT
*
FROM
menu
WHERE ID!=$Id";
$rs3 = mysql_query($sql9) or die(mysql_error());
while($row3 = mysql_fetch_array($rs3)){
$val3=$ParentMenuId?:'';
$selected3 = ($val3 == $row3['ID'] ? 'selected="selected"' : '');
echo '<option value ="' . $row3['ID'] . '"'. $selected3 . '>' . $row3['MenuName'] . '</option>';
}
mysql_free_result($rs3);
}
?>
</select></td>
<td>Link Width</td>
<td><select class="select" name="linkwidth" >
<option value="page" <?php if($LinkWidth = 'page'){ echo 'selected="selected"';}?>>Page</option>
<option value="otherlink" <?php if($LinkWidth = 'otherlink'){ echo 'selected="selected"';}?>>Other Link </option>
</select></td>
</tr>
<tr class="tablerow">
<td>OtherUrl</td>
<td><input type="text" value="<?php echo $OtherUrl;?>" name="otherurl" class=""/></td>
<td>Status</td>
<td><input class="validate[required] radio" type="radio" name="group0" value="1"
<?php if ($Status1 == 1): ?> checked="checked" <?php endif;?> />
<span>Active </span>
<input class="validate[required] radio" type="radio" name="group0" value="0"
<?php if ($Status1 != 1): ?> checked="checked" <?php endif;?> />
<span>De active </span></td>
</tr>
<tr class="tablerow">
<td>OnMainMenu</td>
<td><input type="checkbox" name="onmainmenu" value="1"
<?php if($OnMainMenu == 1) echo "checked='checked'"; else("checked=''"); ?> /></td>
<td>Footer Menu</td>
<td><input type="checkbox" name="footermenu" value="1"
<?php if($FooterMenu == 1) echo "checked='checked'"; else("checked=''"); ?> /></td>
</tr>
<tr class="tableheader">
<td colspan="4" class="last"><input name="insert" type="submit" class="button"
<?php if(!isset($_GET['Id'])){echo "value='Create New'";} else{echo "value='Update'";} ?> />
<input name="reset" type="reset" class="button" value="Reset">
<button type="button" onclick="history.back();" class="button">Back</button> </td>
</tr>
</table>
</form>
<?php
date_default_timezone_set("Asia/Karachi");
if(isset($_POST['insert'])){
$Page_Id =$_POST['pageID'];
$Menu_Name =$_POST['menuname'];
$ParentMenu_Id =$_POST['parentmenuID'];
$Link_Width =$_POST['linkwidth'];
$Other_Url =$_POST['otherurl'];
$State =$_POST['group0'];
$Footer_Menu =$_POST['footermenu'];
$OnMain_Menu =$_POST['onmainmenu'];
if(isset($_REQUEST['linkwidth']) && $_REQUEST['linkwidth'] == 'page'){
if(isset($_REQUEST['pageID']) && $_REQUEST['pageID'] == '0'){
echo"Please Select Any Page";
die;
}
}
if(isset($_REQUEST['linkwidth']) && $_REQUEST['linkwidth'] == 'otherlink'){
if(isset($_REQUEST['otherurl']) && $_REQUEST['otherurl'] == ''){
echo "Please Enter Other Url";
die;
}
}
if($Link_Width=='page'){
$Other_Url="";
}
elseif($Link_Width=='otherlink'){
$Page_Id="";
}
if (isset($Id)){
$sql="UPDATE menu SET PageId='$Page_Id' , MenuName='$Menu_Name', ParentMenuID='$ParentMenu_Id',LinkWidth='$Link_Width',OtherUrl='$Other_Url'
,Status='$State',FooterMenu='$Footer_Menu',OnMainMenu='$OnMain_Menu' WHERE ID='$Id'";
if (!mysql_query($sql)){
die('Error: '. mysql_error());
}
echo "Sucessfully Updated";
header("Location: menu.php");
exit;
}
else{
$query = mysql_query("SELECT MenuName FROM menu WHERE MenuName='$Menu_Name'");
if (mysql_num_rows($query) != 0){
die( "Menu Name already exists");
}
$sql1="INSERT INTO menu ( PageId , MenuName , ParentMenuID , LinkWidth ,OtherUrl , Status, FooterMenu, OnMainMenu )
VALUES ('$Page_Id','$Menu_Name','$ParentMenu_Id','$Link_Width','$Other_Url','$State','$Footer_Menu','$OnMain_Menu')";
if (!mysql_query ( $sql1)){
die('Error: ' . mysql_error());
}
echo "Sucessfully Registers";
mysql_close();
header("Location: menu.php");
exit;
}}
}
include "footer.php";
?>
rjusman90 0 Junior Poster in Training
pritaeas 2,194 ¯\_(ツ)_/¯ Moderator Featured Poster
rjusman90 0 Junior Poster in Training
diafol
rjusman90 0 Junior Poster in Training
diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.