Sensation Energy


United CMS

Documentation - Front

Introduction

What is United CMS ?

FrontEnd has created a website with all the elements you want the user to see. On our FrontEnd there is:

Register page
  • register.php
Login page
  • index.php
Home page
  • ADD blog
  • Blog
  • Category

Register page

Register

Register form

Register page allows user registration

Once users register, they can log in and post their posts. Users who are not registered cannot have any function on the site.

register.php


< ?php
//Here we require the user function
require_once 'fun_user.php';
if($_SERVER['REQUEST_METHOD']==='POST'){
//Here the server requires a post method and if it is
$jsonUsers = getUser(); // get user
//This adds a random id (user_id) to the user
while(true){
//we checked to see if it was correct and if there were already users with that id
$check = true;
//if all is well we add a random user_id
$random=rand(1,2000);
foreach($jsonUsers as $i=>$User){
if($jsonUsers[$i]['user_id']==$random){
//if it is false then it is break
$check=false;
break;
}
}
if($check) break;
}
// here we add a random user_id
$user_id=$random;
$data['user_id']=$user_id;
//Via the post method we take data from the form and enter it in user.json
//The data are:
$data['first_name']=$_POST['first_name'];
$data['last_name']=$_POST['last_name'];
$data['user']=$_POST['user'];
$data['email']=$_POST['email'];
$data['password']=$_POST['password'];
$data['role']=$_POST['role'];
$jsonUsers[sizeof($jsonUsers)] = $data;
//Here we add the user and come back if everything went right to the login page indes.php
addUser($jsonUsers);
header("Location: index.php");
}
//The classic form on which the morisnik enters the data required for registration
//In this case and in all other cases to add optional only name = ""
//name="first_name" which is later used in $data['first_name']=$_POST['first_name'];
// form name="admin" -- $data['admin']=$_POST['admin'];
?>
<form action="" method="post">
<div class="form-group">
<label for="first_name"><h2>First name:</h2></label>
<input type="text" name="first_name"  class="form-input" />
</div>
<div class="form-group">
<label for="last_name"><h2>Last name:</h2></label>
<input type="text" name="last_name" class="form-input" />
</div>
<div class="form-group">
<label for="user"><h2>User:</h2></label>
<input type="text" name="user" class="form-input" />
</div>
<div class="form-group">
<label for="email"><h2>Email:</h2></label>
<input type="text" name="email" class="form-input" />
</div>
<div class="form-group">
<label for="password"><h2>Password:</h2></label>
<input type="password" name="password" class="form-input" />
</div>
<div class="form-group">
<input type="hidden" name="role" value="user">
</div>
<br>
<div align="center">
<div class="btn-group">
<button type="submit" class="btn-3" >POST</button>
<input type="button" class="btn-2" onclick="location.href='index.php';" value="Cancel" />
<!-- it doesn't matter here there is a POST button. The cancel button allows us if we do not register to return our page to indes, php (when we click the cancel button) -->
</div>
</div>
</form>

Login page

Index.php

Login

Login form


<!-- path as login.php where the login function is performed -->
<form action="login.php" method="post">
<div class="form-group">
<!-- Input username -->
<label for="username">Username:</label>
<input type="text" name="user"  class="form-input" />
</div>
<div class="form-group">
<!-- Input password -->
<label for="password">Password:</label>
<input type="password" name="password" class="form-input" />
</div>
<div class="btn-group">
<!-- Nutton "prijava" is metod a method that recognizes the -->
<!-- if loop that the main loop allows the user to log in to later -->
<button type="submit" name="prijava" class="btn-3" >POST</button>
</div>
</form>

Login.php


<?php
// be sure to specify
session_start ();
// this serves us when from the login form where we entered the username and password and click LOGIN
// automatically recognizes that it refers to if "login".
if (isset ($ _ POST ['login'])) {
// This method allows us to transfer the username and password from the form
// The POST method would look like this in our case: $ admin = $ _POST ['admin'];
$ user = $ _POST ['user'];
$ password = $ _POST ['password'];
// function getUser () {allows us to select users from the JSON database.
function getUser () {
// this is the path for the "user.json" database where the list of users with functions is located
$ take = file_get_contents ('user.json');
$ u = json_decode ($ take, true);
return $ u;
}
this allows us to take the user from "user.json"
$ u = getUser ();
foreach ($ u as $ us) {
// This indicates to us if the user does not exist in the database or a username or password has been entered incorrectly not to allow us to listen, but to stay on the login page
if ($ user! = $ _ SESSION ['user']) {
header ('location: index.php');
}
// this means user and role recognition
$ _SESSION ['user'] = $ us ['user'];
$ role = $ us ['role'];
// This de is very important, because from this part starts recognizing the role of users and users themselves
// this if loop indicates if the data entered on the form matches the JSON data (admin = admin) or (user = user)
if ($ user == $ us ['user']) AND ($ password == $ us ['password']) AND ($ role == $ us ['role'])) {
// if the user is an administrator then go to the admin page
if ($ role == 'admin') {
header ('location: admin / index.php');
// if the user is a regular user then the user goes to the page
} else if ($ role == 'user') {
header ('Location: user.php? user ='. base64_encode ($ _ SESSION ['user']));
// base64_encode ($ _ SESSION ['user']) is an encrypted username
} } } } ?>

Index.php is page for login. In this page you can login as admin or user.

Login.php is page for confirmation of the identity of the user entered on the login page with the JSON database, as well as his role.

How to login in CMS? You will do this by typing in the username: "admin" and password: "admin" or username: "user" and password: "user" and pressing "LOGIN" so you will be logged in.

Add blog

Add blog is located at home page. Used to add a blog:

  • Title
  • Subject
  • Date
  • Categoty
Add blog - form

Add blog - form

Add blog - button

Add blog - button

Form - a_b.php


<!-- action = "" does not have its own path because the addition is done on the same page -->
<form action = "" method = "post">
<div class = "form-group">
<!-- hidden user means that the user who is logged in,  is logged in automatically -->
<input type = "hidden" id = "user" class = "form-input" name = "user" value = "&lt;?php echo $ _SESSION ["user"]; ?>">
</div>
<div class = "form-group">
<!-- Input tittle -->
<label for = "title"> Title: </label>
<input type = "text" name = "title" class = "form-input" />
</div>
<div class = "form-group">
<!-- input subject as long text -->
<label for = "subject"> Subject: </label>
<textarea type = "text" name = "subject" class = "form-input"> </textarea>
</div>
<div class = "form-group">
<!-- Input date -->
<label for = "date"> Date </label>
<input type = "date" name = "date" class = "form-input">
</div>
<div class = "form-group">
<!-- category -->
<label for = "cat_id"> Categoty </label>
<select name = "cat_id" id = "cat_id" class = "form-input">
< ?php
// this is the path to the JSON database where we stored the category names
$take = file_get_contents ('category.json');
$test = json_decode ($ take, true);
foreach ($ test as $ government) {
// here we select the desired category from the JSON database that we entered earlier
echo "<option value = '$government [cat_id]'> $ government [cat_title] </option>";
} ?>
</select>
</div>
<div class = "btn-group">
<!-- dugamd is the first when you press you add a blog, and the second is if it gives up and automatically returns you to the home page -->
<button type = "submit" class = "btn-3"> POST </button>
<input type = "button" class = "btn-2" onclick = "location.href = 'index.php';" value = "Cancel" />
</div>
</form>


Add function


<?php
require_once 'fun_blog.php';
// this is the path to the blog function
if($_SERVER['REQUEST_METHOD']==='POST'){
// add a random "id" to this mode
$jsonUsers = getBlog();
while(true){
$check = true;
$random=rand(1,2000);
foreach($jsonUsers as $i=>$osoba){
if($jsonUsers[$i]['id']==$random){
$check=false;
break;
}
}
if($check) break;
}
$id=$random;
// as we explained in the login tutorial here via the post method we add the following:
$data['id']=$id;
$data['cat_id']=$_POST['cat_id'];
$data['user']=$_POST["user"];
$data['title']=$_POST['title'];
$data['subject']=$_POST['subject'];
$data['date']=$_POST['date'];
// this allows us if we can enter everything to have our blog subscribed
$jsonUsers[sizeof($jsonUsers)] = $data;
addBlog($jsonUsers);
// when we have done everything well through this method it takes us back to the home page
header("Location: index.php");
}
?>


How do we add a blog? We will add the blog by clicking on the other "add bloblog", and then the page will open where you will fill in the form with Title, Subject, Date and Categoury, and then click on the "POST" button. This is how you added the blog.

Blog

Mysql

Blog

A blog is part of the United CMS that allows you to write various things that interest you. Also, the blog contains a category that we added earlier.

How our blog works? When you add a blog, the following appears on your home.php page:

  • Title
  • Subjcet or posts (summary)
  • User (blog writer)
  • Date blog was written
  • The blog also contains a page we called the "subject".

    What is "subject" or post?

    Subject is page which contains the entire content of your blog.

    How do we come to page "subjects"?


    Subject

    Subject or posts

    Blog

    
      < ?php
      require_once 'fun_blog.php';
      // we take the blog function
      $bl = getBlog ();
      // with this function we warm up as many posts as we want to appear on one page
      $nb_elem_per_page = 2;
      $page = isset ($ _ GET ['page'])? intval ($ _ GET ['page'] - 1): 0;
      $number_of_pages = intval (count ($ bl) / $ nb_elem_per_page) +1;
      foreach (array_slice ($ bl, $ page * $ nb_elem_per_page, $ nb_elem_per_page) as $ b) {
      ?>
      // here is the title
      <h1> <a href="subject.php?id=< ?php echo $b['id'];?> "> < ?php echo $b ['title']; ?> </a> </h1>
      // here is the subject
      <h2> < ?php echo $b ['subject']; ?> </h2>
      here is the user who wrote the blog
      <h2> < ?php echo $b ['user']; ?> </h2>
      here is the date the blog was written
      <h3> < ?php echo $b ['date']; ?> </h5>
      <hr>
    < ?php }; ?>
      // this is a function that determines how many pages our blog will have
      <div class = "pagination">
      < ?php
      if (isset ($page)) {
      // Pages are defined here, if you are on the home page then you can only go to the next page
      for ($i = 1; $i <$number_of_pages; $i ++) {
      if ($page <= 1) {
      echo "<a href='./?page=$i'class=active> </a> <br>";
      } else {
      // this applies to the opposition if you are on a third page, for example, so you can go to the other side or go to the fourth side
      $i = $page-1;
      echo "<a href='./?page=$i'> <button class = 'btn-circle'> <i class = 'fa fa-angle-left'> </i> </button> </ a > <br> ";
      }
      // number_of_pages allows you to show how many pages there are
      for ($i = 1; $i <= $number_of_pages; $i ++) {
      if ($i <> $page){
      echo "<a href='./?page=$i'> $i </a> <br>";
      } else {
      echo "<a href='./?page=$i'class=active>". $i. "</a> <br>";
      } }
      if ($page == $number_of_pages) {
      echo "<a href='./?page=$i'class=active> </a> <br>";
      } else {
      $i = $page + 1;
      }}}?>
    
    

    By clicking on the "title" and we will get to the page via the link


    Click on title

    Click on title

    Posts subject.php

    
    < ?php
    //function post
    //This allows us to take data for our post
    function getBlog(){
    $get = file_get_contents('blog.json');
    $blog = json_decode($get,true);
    return $blog;
    }
    $bl = getBlog();
    foreach($bl  as $c){
    if(isset($_GET['id'])){
    //This allows us to show the desired post using "id"
    //Get function allows us to have an id blog recognize an id post
    //For example my id is one and when you open a post, the id value of the post is 1
    $id = $_GET['id'];
    }
    if ($c['id'] == $id){
    $c = $c;
    //Here we equate id from get method with id from blog
    ?>
    <!-- title, user, subjcet and date are displayed here
    of course which belongs to the blog by the value of "id" -->
    <h2>< ?php echo $c['title']; ?></h2>
    <h2>< ?php echo $c['user']; ?></h2>
    <h2>< ?php echo $c['subject']; ?></h2>
    <h2>< ?php echo $c['date']; ?></h2>
    < ?php } }; ?>
    
    

    Category


    Category

    Category

    This category is used to sort the blog.

    When you add a blog, be sure to add a category, so that later when you select the desired category, only the posts that you selected from the category will come out.

    We add, delete or edit a category from the admin panel.

    When you click on the desired category in the subject page only opened posts that link to the selected category.


    17ry ID

    Category ID

    Category

    
      < ?php
      //Function for get blog
      function getBlog(){
      $get = file_get_contents('blog.json');
      $blog = json_decode($get,true);
      return $blog;
      }
      $category = getBlog();
      foreach($category  as $c){
      //Same as for post categories lists all posts that are related to the selected category via "id"
      //Example if you select the category "PHP" and you will go to the page kategory.php you will see all the posts related to the category "PHP"
      if(isset($_GET['cat_id'])){
      //This is if the category id for example has a value of 1
      //Using the GET method you take the value id = 1
      $cat_id = $_GET['cat_id'];
      //Here you equate that id value from the get method with the id from the category
      }
      if ($c['cat_id'] == $cat_id){
      $c = $c;
      //For example id = 1 = id = 1 this is an example where 1 = 1 and all posts related to 1 will be listed
      ?>
      <!-- Title, user, subjcet and date are displayed here
      of course which belongs to the category by the value of "id" -->
      <h2>< ?php echo $c['title']; ?></h2>
      <h2>< ?php echo $c['user']; ?></h2>
      <h2>< ?php echo $c['subject']; ?></h2>
      <h2>< ?php echo $c['date']; ?></h2>
      < ?php } }; ?>
    
    

    Content


    Documentation


    Answer the following question:

    You must be logged in


    Chapters


    1. Chapter: FrontEnd Page (Blog & Category)

    2. Chapter: BackEnd Page (Admin dashboard)

    3.
    Chapter: User profile

    4.
    Chapter: JSON Database


    Advertising