Tuesday, 22 April 2014

CMS PHP BASIC PROJECT SESSION ADMIN USER PANEL






 SQL FILE

 CREATE TABLE  `basic_cms`.`menus` (
`m_id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`m_title` VARCHAR( 50 ) NOT NULL ,
PRIMARY KEY (  `m_id` )
) ENGINE = INNODB


CREATE TABLE  `basic_cms`.`pages` (
`p_id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`p_title` VARCHAR( 100 ) NOT NULL ,
`p_desc` TEXT NOT NULL ,
PRIMARY KEY (  `p_id` )
) ENGINE = INNODB


CREATE TABLE  `basic_cms`.`admin_login` (
`u_id` INT( 10 ) NOT NULL AUTO_INCREMENT ,
`user_name` VARCHAR( 30 ) NOT NULL ,
`user_pass` VARCHAR( 30 ) NOT NULL ,
PRIMARY KEY (  `u_id` )
) ENGINE = INNODB

INSERT INTO  `basic_cms`.`menus` (
`m_id` ,
`m_title`
)
VALUES (
NULL ,  'News'
), (
NULL ,  'Showbiz'
), (
NULL ,  'Cricket'
), (
NULL ,  'Blogging'
), (
NULL ,  'Seo Tips'
);










/////includes/db.php
<?php

$con = mysql_connect("localhost","root","");
$db = mysql_select_db('basic_cms', $con);

?>

///////////////////////////////
////////index.php



<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />

    <title>Basic CMS</title>
   
    <style type="text/css">
    a:link{
    color: white;
    text-decoration:none;
    }
   
   
    h2{
        color:red;
        margin: 5px;
        padding:5px;
        font-size:28px;
        text-decoration:underline;
        text-align: center;
       
    }
   
    </style>
   
   
   
</head>

<body>
<table width='990' border='2' align='center'>
<!---Header Starts----->
<tr>
<td> <?php include ("includes/header.php"); ?></td>
</tr>

<!---Navigation Starts----->
<tr>
<td >
<table border='0'>

<?php
include ("includes/db.php");

$query = "select * from menus";
$run = mysql_query($query);

while($row = mysql_fetch_array($run)){
   
    $m_title = $row[1];
   
    echo "<td bgcolor='black'width='100'  align='center'>
    <a href='pages.php?pages=$m_title'> $m_title</a> </td>   ";



}



?>


</table>

</td>
</tr>

<!---Main Contant Starts----->
<tr>
<td bgcolor='pink' height='500' valign='top'>
<h2>Welcome to my website</h2>
<p>This website for all users who wants to learn php in advanceThis website for all users who wants to learn php in advanceThis website for all users who wants to learn php in advanceThis website for all users who wants to learn php in advanceThis website for all users who wants to learn php in advanceThis website for all users who wants to learn php in advance </p>

<center><img src="sanam.jpeg"></img></center>


</td>
</tr>
<!---Footer Starts----->
<tr>
<td bgcolor='black' height='60' align='center'>
<h2 style='color:white;'>Created by Aamir Javed</h2>

</td>
</tr>



</table>
</body>
</html>

///////////////////////////////////////////////////////////////////////////////////////////////////////////
//pages.php



<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />

    <title>Basic CMS</title>
   
    <style type="text/css">
    a:link{
    color: white;
    text-decoration:none;
    }
   
   
    h2{
        color:red;
        margin: 5px;
        padding:5px;
        font-size:28px;
        text-decoration:underline;
        text-align: center;
       
    }
   
    </style>
   
   
   
</head>

<body>
<table width='990' border='2' align='center'>
<!---Header Starts----->
<tr>
<td> <?php include ("includes/header.php"); ?></td>
</tr>

<!---Navigation Starts----->
<tr>
<td >
<table border='0'>

<?php
include ("includes/db.php");

$query = "select * from menus";
$run = mysql_query($query);

while($row = mysql_fetch_array($run)){
   
    $m_title = $row[1];
   
    echo "<td bgcolor='black'width='100'  align='center'>
    <a href='pages.php?pages=$m_title'> $m_title</a> </td>   ";



}



?>


</table>

</td>
</tr>

<!---Main Contant Starts----->
<tr>
<td >

<table border='0' width='800' align='center' >

<tr>
<?php
$pages = $_GET['pages'];
$query = "select * from pages where p_title='$pages' ";
$run = mysql_query($query);
while ($row = mysql_fetch_assoc($run)){
   
 echo "<td bgcolor='aqua' >" . "h2" . $row['p_title']. "</h2>". $row['p_desc']."</td>";  
   
   
}




?>

</tr>

</table>

</td>
</tr>
<!---Footer Starts----->
<tr>
<td bgcolor='black' height='60' align='center'>
<h2 style='color:white;'>Created by Aamir Javed</h2>

</td>
</tr>



</table>
</body>
</html>


//////////////////////////////////////////////////////
//admin_panel.php


<?php

 session_start();

if(!$_SESSION['admin_name'] ){
   
    header('location:login.php?error= You are not administrator');
   
}


?>



<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />

    <title>Admin Panel</title>
</head>

<body>

<div style='width:100%; height: 100px; background: blue; text-align: center; font-size:33px; color:white;'>
Welcome to admin panel

</div>
Welcome: <font size='4' color='red'>
<?php

echo $_SESSION['admin_name'];

?>

</font>
<h2><a href='logout.php' style="margin-top: 10px;">Logout!</a></h2>

<h2 align= 'center'><?php echo @$_GET['deleted'] ?></h2>

<h2 align= 'center'><?php echo @$_GET['inserted'] ?></h2>

<h2 align= 'center'><?php echo @$_GET['logged'] ?></h2>

<h2><a href='admin_panel.php?view_page=view page'>View Pages</a></h2>
<h2><a href='insert_page.php'>Insert New Page</a></h2>
<h2><a href='admin_panel.php?view_menu=view menu'>View Menu</a></h2>
<h2><a href='insert_menu.php'>Insert New Menu</a></h2>

<?php


include ("includes/db.php");

if(isset($_GET['view_page']))
{
   
   
   


?>

<table width='1000' border='2' align='center' >

<tr>
<td align='center' bgcolor='yellow' colspan='6'><h2> All pages here !</h2></td></tr>

<tr align='center'>
<th>Page No.</th>
<th>Page Title</th>
<th>Page Content</th>
<th>Delete</th>
</tr>


<tr>
<?php
//$page = $_GET['view_page'];
$query = "select * from pages ";
$run = mysql_query($query);

while($row = mysql_fetch_array($run) )
{
   
    $p_id = $row['p_id'];
    $p_title = $row['1'];
    $p_desc = substr($row['2'],0,100);


?>


<td><?php echo $p_id;   ?></td>
<td><?php echo $p_title;  ?></td>
<td><?php  echo $p_desc; ?></td>
<td><a href='delete_page.php?del_page=<?php echo $p_id; ?> '> Delete</a></td>
</tr>
<?php

}}

?>

</table>


<?php

if(isset($_GET['view_menu']))
{

?>

<table width='400' border='3' align='center'>

<tr>
<td colspan='5' bgcolor='aqua' align='center'><h2>All menus here</h2></td>
</tr>


<tr align='center'>
<th>Menu No:</th>
<th>Menu Title:</th>
<th>Delete</th>
</tr>



<?php

 $query = "select * from menus";
 $run = mysql_query($query);

while ($row= mysql_fetch_array($run))
{

$m_id = $row['m_id'];
$m_title = $row[1];   


?>

<tr align='center'>


<td><?php echo $m_id ?></td>
<td><?php echo $m_title ?></td>
<td><a href='delete_menu.php?del_menu=<?php echo $m_id;  ?>' >Delete</a>   </td>
</tr>

<?php }}  ?>


</table>


</body>
</html>


//////////////////////////////
///insert_page.php


<?php

 session_start();

if(!$_SESSION['admin_name'] ){
   
    header('location:login.php?error= You are not administrator');
   
}


?>

<html>
<?php
include ("includes/db.php");
include ("admin_panel.php");



?>


<form action='' method='post'>
<table width='500' border='3' align='center'>

<tr>
<td colspan='4' bgcolor='pink' align='center' > <h2>Insert New Page</h2></td>
</tr>

<tr>
<th>Page Title:</th>
<td><input type='text' name='page_title'></td>
</tr>

<tr>
<th>Page Content:</th>
<td><textarea name='page_content' cols='20' rows='10'></textarea>
</td>
</tr>

<tr>
<td align='center' colspan='6'> <input type='submit' name='submit' value='submit'/></td>

</tr>




</table>



</form>
</html>

<?php


if(isset($_POST['submit'])){
   
    $post_title = $_POST['page_title'];
     $post_content = $_POST['page_content'];
    
     $query = "insert into pages (p_title,p_desc) values ('$post_title','$post_content') ";
    
    
   if(mysql_query($query))
  
   {
  echo "<script>window.open('admin_panel.php?inserted=A new page has been inserterd','_self') </script>";
       
     }
    
    
         
}


//////////////////////////////////
//delete_page.php

?>


<?php
include ("includes/db.php");

$delete_page = $_GET['del_page'];

$query = "delete from pages where p_id='$delete_page'";

if(mysql_query($query)){

echo "<script>window.open('admin_panel.php?deleted= Your page has been deleted....','_self')</script>";  



   
}


?>

 ////////////////////
 //delete_menu.php


<?php
include ("includes/db.php");
$delete_menu = $_GET['del_menu'];
$query = "delete from menus where m_id='$delete_menu'";
if(mysql_query($query)){
echo "<script>window.open('admin_panel.php?deleted=Your Menu has been deleted....','_self')</script>";  
}
?>


////////////////////////////////////////////////
//login.php


<?php
session_start();
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta http-equiv="content-type" content="text/html" />
    <meta name="author" content="gencyolcu" />
    <title>Admin Login</title>
</head>
<body>
<form action='login.php' method='post' >
<table width='400' align='center' border='5' >
<tr>
<td colspan='5' align='center' bgcolor='green' >
<h2>Admin Login</h2>
</td>
</tr>
<tr>
<th aligin='right'>User Name:</th>
<td><input type='text' name='admin_name' /></td>
</tr>
<tr>
<th aligin='right'>User Password:</th>
<td><input type='text' name='admin_pass' /></td>
</tr>
<tr>
<td colspan='6' align='center' >
<input type= 'submit' name='submit' value='Login' />
</tr>
</table>
</form>
<h2 align='center'><?php echo @$_GET['logout'] ?></h2>
<h2 align='center'><?php echo @$_GET['error'] ?></h2>
</body>
</html>
<?php
include ("includes/db.php");
if(isset($_POST['submit']))
{
   $admin_name = $_SESSION['admin_name']= $_POST['admin_name'];
    $admin_pass = $_POST['admin_pass'];
 $query = "select * from admin_login where user_name ='$admin_name' AND user_pass ='$admin_pass'";
   $run = mysql_query($query);
    if(mysql_num_rows($run)==1){
echo "<script>window.open('admin_panel.php?logged= You are Loggedin Successsfully!','_self') </script>";
    }
else
{
    echo "<script> alert('User Name or passwrd is incorrect')</script>";
}   
}
?>


///////////////////////
//logout.php


<?php
session_start();
session_destroy();
header('location: login.php?logout= You have loggedout! Come Back soon....');
?>




No comments:

Post a Comment