Universal PHP Admin - User guide

About

Universal PHP Admin is a php script that is created to manage any type of php application or website. It provides a flexible backend or content management system (CMS) that can be easily customized to manage a blog, a gallery, a poll e.t.c. It comes with its own user authentication system that allows for granular management of the access that the users have to the backend. With this script you will not have to keep creating backends for every php project from scratch.

Features

  • Create a backend for any PHP application in minutes
  • Easy to configure
  • Integrated user authentication system
  • Easy to add your own validation and actions

 

 

 

 

 

Installation

  1. Unzip the package.
  2. Upload the folder named "universal_admin" to you server
  3. Open the includes/settings.php. Change the information for your database and domain and other settings
  4. Navigate to the install.php file to create the first admin account.
  5. Delete the install.php file and then navigate to the login.php file.

That's it!

If you're new to Universal PHP Admin, please read the Getting Started section to begin using Universal PHP Admin.

 

 

 

 

 

Getting Started

Once Universal PHP Admin has been installed you will been to configure it so that it can your specific application. Universal PHP Admin is design with the assumption that all the objects in your application have a corresponding table in your database. Configuring Universal PHP Admin entails defining the tables for these objects and their fields

To start configuring Universal PHP Admin, just sign in and click on the configure link at the top-right area on the Admin dashboard.

DEFINING TABLES

First we will need to add a table. To define a table all you need is the table's name and a display name that will be convinient for users. For example, lets say that you have a poll application that you need to manage and the poll questions are saved in a table named mysite_polls. You would define this table by providing its name as mysite_polls and a display name Polls.

After you click save you will then be directed to define the fields for this table.

For your own convinence you will need to start by defining tables that are not linked to other tables. For example if you have a table for polls questions and another for the choices for these questions, you would need to start by defining th table for the polls and then the one for the choices.

DEFINING FIELDS

To define a field you will need to provide the following information. Please read this section carefully.

  • name: This is the name of the field in the table. REQUIRED
  • display name: This is a more userfriendly name that you can give the field.
  • input widget: You will need to select the best widget that will best suit the field in the forms for adding and changing the object.
  • is it required: If the field is always required you will need to check the checkbox.
  • use as string representation of record: For example, when the images in a gallery are listed the user can most easily identify the images by the titles they have been given. The title would therefore be the string representation of the object and when you defined the title you would check this check box. Every table requires only one field to be the string representation of the object.
  • Is it visible on the change list page: Will this field be displayed on the change list page (The page that lists the records of a table)?

Depending on the input widget that you will have selected for a field you may be needed to provide additional information:

Checkbox:
A checkbox widget require you to specify the value that will be saved if it is checked and another value if the the checkbox is not checked. You will also need to specify if it is checked or not by default

Foreign Key:
For this widget you will need to select the table to which this field is linked to.

Date/Time :
You will need to specify the format that will be used to save the date. The format should be the PHP style, i.e. D F j, Y, g:i a. If this value is not provided then the timestamp is saved. You could also choose to make it that the field is automatically filled with the current timestamp when a record is created or updated

Upload File:
You will need to specify the path to the folder where the uploaded file will be saved. This path need to be relative to the administration folder of the Universal PHP Admin package. You will also need to specify the allowed file extensions in this format: png|jpg|gif|swf

Select options:
You will need to specify the options This widget will use the select form element. For each option that can be selected you will need to specify the value that will be displayed and the value that will be saved. For example, lets say that you want to save the gender of a person as F or M but you want the person that will input the information to see either Female or Male. You will need to input the options as

The widget in the add and change forms will look like this

Note: Each tables needs one field to be the primary key and one field to be the string representation. If either of these two is missing then the table is not displayed in the Admin Dashboard

Once you have defined the tables and their fields then you can start managing them from the dashboard

 

 

 

 

 

User authentication

In the Admin Dashboard there are 3 area that can be accessed:

  • Authentication: The pages that can be used to add, change and delete users, roles and permissions
  • Configuration: The pages that are used to configure the tables and the fields.
  • Tables: The pages that are used to add, change and delete the objects/items

The things that a user can do in the Dashboard can be controlled using the permissions that their roles have.

Everytime a table is defines permissions to add, change and delete the table's items are also automatically created.

The authentication system can also be used to manage pages that are not part of the admin dashboard. To do this all you need to do is:

  1. Define the permission for the pages.
  2. Define a role that has the permission
  3. Assign the users that will access the pages the role
  4. Include the the file includes/admin.php in the pages that you need to restrict access to.
  5. Create an instance of the Admin class: <?php $admin = new Admin(); ?>
  6. Place the following php script at the top of the page:
    <?php
    if(!$admin->user_has_role('role name')){
    header('Location: the_login_file.php'); // this is a page of your choosing
    exit();
    }
    ?>
  7. There is also a function for checking for a permissions:
    <?php $admin->user_has_permission('permission_key') ?>

To access user information from the session variables:

  • User id: $_SESSION['sadmin_user_id']
  • User email: $_SESSION['sadmin_user_email']
  • User role id: $_SESSION['sadmin_user_role']

 

 

 

 

 

Customization

You can further customize Universal PHP Admin adding your own validation rules for input and actions to be performed on items.

Validation

To add you own validation you will need to first add a function for doing the validation in the file includes/validation.php. The function should be something like this:

After you have created the function, add its details to the __construct() function of the class like this:
$this->validation_functions[] = array('table'=>'the_table_name', 'field' => 'the_field_name', 'function'=>'the_function_name');

That is all it takes.

Actions

Actions can be performed on items in the change list.

To add an action you will need to first add the function in the file includes/actions.php. The function should be something like this:

After you have created the function, add its details to the __construct() function of the class like this:
$this->action_functions[] = array('table'=>'the_table_name', 'function_name'=>'the_function_name', 'display_message'=>'The name for the action to in the select list');

That is all it takes.

 

 

 

 

 

Styling

The following are the styling changes that you might want to make:

  • Admin dashboard pages: The styling for these can be change in the file administration/assets/css/style.css.
  • The log in pages: The styling for these can be change in the administration/assets/css/login.css

 

 

 

 

 

Updating

  1. Download and unzip the package
  2. If you have made changes to includes/actions.php or includes/validation.php, then replace these two files in the new package with the ones you have changed
  3. Open the includes/settings.php. Change the information for your database and domain and other settings
  4. Back up you old files
  5. Upload the new package
  6. Your script is now updated.

 

 

 

 

 

Translation

This script has been prepared for translation. To translate it, simple follow these instructions.

  1. Go to the folder includes/language/
  2. Make a copy of the folder english and rename it to the language of your choice.
  3. Open the folder you have just created and you will find a number of php files that define array elements for the text that the script displays.
  4. One by one make changes to each of the array elements in all of the files.
  5. When you are done translating open the includes/settings.php. Change line 40 $config['language'] from english to the name of the folder you just create and you are done.