Cadre – PHP Staff Management System (Free Download)

Cadre is an open-source PHP Staff Management System. This is not a system with a ton of “brutal features” that you will never use. Cadre is a simple system that will help small companies to get started quickly.

 

TABLE OF CONTENTS

 

 

DOWNLOAD & INSTALLATION

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

 

INSTALLATION

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

 

 

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 “Staff” 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, assigned the entitled leave of all the staff members.

P.S. The “types of leave” can only be modified in the settings database table, LEAVE_TYPES.

 

 

PART 3) DEFINE HOLIDAYS

The once-every-year hassle – Define the holidays.

 

PART 4) APPLY FOR LEAVE

  • To apply for leave, simply go under “My Leave”.
  • Hit the + button > Select the type of leave > Select the period > Confirm the individual days.

 

PART 5) APPROVE/DENY LEAVE

Finally, to permit or reject the leave application.

 

CADRE FAQ

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

 

I DELETED ALL ADMIN ACCOUNTS

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

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

 

CHANGED DOMAIN OR PATH

  • 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/cadre/
  • Delete the existing .htaccess file.
  • Create init.php.
    • require "lib/CORE-Go.php";
    • $_CORE->Route->init();
  • Access http://site.com/init.php, this will automatically regenerate the .htaccess file.
  • Delete init.php.
  • Clear the service worker and browser cache if you want to be “totally safe”.

 

PAGES ARE NOT RESOLVING OR SHOWING PROPERLY

  • Make sure that MOD_REWRITE is enabled in Apache.
  • Make sure that AllowOverride is set properly in Apache.
  • If using https://, make sure that your SSL cert and virtual host are properly set.
  • In Mac/Linux, make sure that Apache/PHP has permission to read the files and folders.

Here is a quick “working example” of a test site on my WAMP server:

httpd.conf OR httpd-vhosts.conf
<VirtualHost site.com:443>
  DocumentRoot "D:\http"
  ServerName site.com:443
  SSLEngine On
  SSLCertificateFile "C:/xampp/apache/conf/ssl.crt/server.crt"
  SSLCertificateKeyFile "C:/xampp/apache/conf/ssl.key/server.key"
  <Directory "D:\http">
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

 

MANUAL INSTALLATION

  • Create a database and import all lib/SQL-*.sql in ascending order..
  • 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.
    • Set your own JWT secret key, and the issuer to your domain or company name.
  • Run $_CORE->Route->init() 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.

 

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 – Forgotten password recovery.
Field Description
user_id User ID, primary and foreign key.
reset_hash Password reset security hash.
reset_time Timestamp when the reset request is made. Spam prevention.

 

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.

Leave a Comment

Your email address will not be published. Required fields are marked *