Cadre – Simple PHP Staff Management System (Free Download)

Cadre is a free and open-source PHP Staff Management System. Not the best in the world, but this simple portal has the basic features to help small companies to get started quickly.

 

TABLE OF CONTENTS

Download & Notes How To Use Quick Reference
How To Develop Common Problems

 

 

DOWNLOAD & NOTES

First, here are the download links and a quick “setup guide” for the impatient folks who don’t have the patience to read through everything.

 

LICENSE & DOWNLOAD

Cadre is released under the MIT License. You are free to use it for personal and commercial projects, and modify it as you see fit. On the condition that the software is provided “as-is”. There are no warranties provided and “no strings attached”. Code Boxx and the authors are not liable for any claims, damages, or liabilities.

Download Cadre | GitHub | SourceForge

 

SYSTEM REQUIREMENTS

  • LAMP/WAMP/MAMP/XAMPP
  • Apache Mod Rewrite
  • PHP MYSQL PDO Extension
  • At least PHP 8.0

Cadre has not been extensively tested, but it is developed and works on a WAMP8 (Windows Apache MySQL PHP 8) server.

 

INSTALLATION

Just access http://your-site.com in your browser and walk through the installer.

 

FEATURES

  • Manage staff – Add/update/suspend.
  • Manage leave – Apply, approve, and deny.
  • Progressive web app.

 

 

HOW TO USE

So far so good? Let us now go through a quick crash course on how to use Cadre.

 

PART 1) REGISTER USERS

The first thing you want to do is to register the users. Go under the “Users” section, and add them. There are 3 “types of users”:

  • Admin – Has full access to all the system features.
  • User – Can only apply for leave and check the status.
  • Suspended – For security and data integrity, there will be no deletion of user data… Only suspended user accounts.

 

PART 2) ASSIGNING ENTITLED LEAVE

Next, assign the users entitled leave… Or they won’t be able to apply for leave.

P.S. Also remember to define the holidays under “Leave” > “Holidays”.

 

 

PART 3) APPLY FOR LEAVE

Straightforward process.

  • For admin, this is under Leave > “My Leave”.
  • For users, this is under “My Leave”.

Just hit the “+” button, select the type of leave and period, and confirm the individual days.

 

PART 4) APPROVE/DENY LEAVE

An admin-only feature. Hit “cross” to deny the leave, and “check” to approve the leave.

 

QUICK REFERENCE

This section is for the developers, a quick walkthrough of the general system structures.

 

FOLDER STRUCTURE

  • assets/ Public images, Javascript, CSS, etc…
  • lib/ Core engine and library files.
    • API-AAA.php The API endpoints. Will be deployed at http://site.com/api/AAA/.
    • CORE-CCC.php Core engine files. Try not to mess with these.
    • LIB-LLL.php Library files.
    • SQL-SSS.php SQL database files. Can actually delete these after installation.
  • pages/ HTML pages and template.
    • ADM-AAA.php Admin pages. Will be deployed at http://site.com/admin/AAA/.
    • USR-UUU.php Staff pages. Will be deployed at http://site.com/staff/UUU/.
    • PAGE-PPP.php “Normal” pages. Will be deployed at http://site.com/PPP/.
    • MAIL-MMM.php Email templates.
    • TEMPLATE-TTT.php HTML page template.

 

THE FRAMEWORKS

Cadre is built with:

 

 

DATABASE TABLES

USERS & PASSWORD

users
Field Description
user_id Primary key, auto-increment.
user_name Full name.
user_title Title. E.g. Manager, Developer, Accoutant, etc…
user_email Email, unique.
user_password Password, encrypted.
user_level Access level.

  • “A” – Admin
  • “U” – User
  • “S” – Suspended
password_reset
Field Description
user_id Primary and foreign key.
reset_hash Automated password reset security hash.
reset_time The time when the reset request is made.

 

SYSTEM

settings
Field Description
setting_name Primary key.
setting_description Description of the setting.
setting_value The value of the setting.
setting_group Setting group.

  • 0 – “Hidden” system settings and definitions.
  • 1 – User changeable settings.

 

LEAVE

holidays
Field Description
holiday_id Primary key, auto-increment.
holiday_name Holiday name.
holiday_date Holiday date.
holiday_half 1 for half day, 0 for full day. E.G. New Year’s Eve may be a half-day holiday.
leave_entitled
Field Description
user_id Foreign key and composite primary key.
leave_type Composite primary key.

  • “M” – Medical
  • “P” – Paid
  • “U” – Unpaid
leave_days The number of days entitled for this leave type.
leave_taken
Field Description
leave_id Primary key, auto-increment.
user_id Foreign key.
leave_type Type of leave taken.
leave_from Leave starting from.
leave_to Leave ending.
leave_days The total number of days.
leave_type Type of leave.
leave_status Status of this leave.

  • “P” – Pending
  • “A” – Approved
  • “D” – Denied
leave_taken_days
Field Description
leave_id Composite primary key and foreign key.
leave_day Composite primary key. Day of leave.
leave_half Full or half day.

  • 1 – Full day
  • A – AM
  • P – PM

 

 

LEAVE CALCULATION RULES

  • Holidays, Saturdays, and Sundays are considered “not a working day”.
  • The number of leave days is counted based on the start date. E.G. From 30 Dec 2022 to 6 Jan 2023 will fall under 2022.

If you want to change the leave calculation rules, you will have to manually update:

  • The library – lib/LIB-Leave.php
  • All the related leave pages – pages/ADM-leave-*.php and pages/USR-leave-*.php

 

DEVELOPING “CADRE”

As simple as it may be, going through the entire system is still going to take some time. So instead of “explaining line-by-line”, here is a condensed version of “how to quickly customize and upgrade”.

 

CORE BOXX LIBRARY REFERENCE

For most of the core modules, you can refer to the Core Boxx reference library.

 

STEP 1) CREATE/MODIFY DATABASE TABLES

Add new tables or views. Modify the existing ones as required.

 

STEP 2) ADD/UPDATE SYSTEM MODULES

lib/LIB-Report.php
class Report extends Core {
  function getJobs ($id) {
    return $this->DB->fetchAll(
      "SELECT * FROM `jobs` WHERE `company_id`=? ORDER BY `job_id` DESC",
      [$id]
    );
  }
}

To add a new module:

  • Create lib/LIB-Module.php.
  • Define class Module extends Core.
  • Add functions inside.

In this example, we added a new report module – lib/LIB-Report.php and class Report extends Core. That’s all. This new module can now be loaded via $_CORE->load("Report") and the function can be accessed via $_CORE->Report->getJobs().

 

STEP 3) ADD/UPDATE API ENDPOINT (OPTIONAL)

lib/API-report.php
// (A) ADMIN ONLY
if (!isset($_SESS["user"]) || $_SESS["user"]["user_role"]!="A") {
  $_CORE->respond(0, "Please sign in first", null, null, 403);
}

switch ($_REQ) {
  // (B) INVALID REQUEST
  default:
    $_CORE->respond(0, "Invalid request", null, null, 400);
    break;
 
  // (C) GET JOBS
  case "getJobs":
    $_CORE->autoGETAPI("Reports", "getJobs");
    break;
}}

To add an API endpoint:

  • Core Boxx has an API structure of http://site.com/api/MODULE/REQUEST.
  • lib/API-report.php will create an API endpoint at http://site.com/api/report.
  • $_REQ is the requested service REQUEST segment of the URL.

So for this example, we can send $_POST["id"] = 123 to http://site.com/report/getJobs/ to get the jobs report. The API will reply with a JSON encoded string.

 

 

STEP 4) ADD/UPDATE HTML CSS JAVASCRIPT

  • Add your new pages in pages/.
    • For admin pages, add pages/ADM-name.php.
    • For user pages, add pages/USR-name.php.
    • For “normal” pages, add pages/PAGE-name.php.
    • For example, pages/ADM-report.php can only be accessed by administrators from http://site.com/admin/report.

That’s about it. Just reverse engineer and copy from the existing libraries, API, and pages… You will see the development pattern here.

 

COMMON PROBLEMS & FIXING THEM

Cadre is “not working”? Here are a few of the common problems and how to “fix” them.

 

I FORGOT THE PASSWORD (OR DELETED ALL ADMIN ACCOUNTS)

recover.php
require "lib/CORE-Go.php";
$_CORE->load("Users");
$_CORE->Users->save("NAME", "TITLE", "EMAIL", "PASSWORD", "A", OPTIONAL-USER-ID);

Just create an “account recovery” script to create a new account (or update an existing one). Run and delete this afterward.

 

CHANGED DOMAIN OR NOT RESOLVING PROPERLY

  • Update HOST_BASE in lib/CORE-Config.php. Make sure to include the path (with a trailing slash) if not deployed at the base URL. E.G. http://site.com/coreboxx/
  • Create an “update script”, run it, and delete it afterward.
    • require "lib/CORE-Go.php";
    • $_CORE->Route->htaccess();
    • This will automatically regenerate the .htaccess file.
  • Clear the browser cache to prevent irritating cache redirects.
  • Also, clear the service worker and cache storage if you want to be “totally safe”.

 

MANUAL INSTALLATION

  • Create a database and import all lib/SQL-*.sql.
  • Open lib/CORE-Config.php, update the settings to your own.
    • The host settings.
    • Database settings.
    • If you want to develop mobile apps, consider enabling CORS.
    • Generate your own JWT secret key, and set the issuer to your domain or company name.
  • Run $_CORE->Route->htaccess() to create .htaccess.
  • Create your own admin user. See “forgot password” above.
  • Update index.php.
    • require __DIR__ . DIRECTORY_SEPARATOR . "lib" . DIRECTORY_SEPARATOR . "CORE-Go.php";
    • $_CORE->load("Route");
    • $_CORE->Route->run();

 

NOT WORKING. DON’T KNOW WHY.

Open the developer’s console, reload the page and share the error message.

How To Debug Javascript (A Very Simple Guide)

How to Debug PHP Code (A Very Simple Guide)

Leave a Comment

Your email address will not be published.