National Scholarship Portal 2025
Post by : admin | Date : 2026-01-05
Perfect π
Since youβre using Core PHP + MySQL, below is a complete, practical project structure + requirement checklist that you can directly start coding from.
Iβll keep this implementation-oriented, not theoretical.
1οΈβ£ What You Will Need (Checklist)
A. Server & Environment
- PHP 8.x
- MySQL 5.7+ / 8.0
- Apache / Nginx
- SSL (HTTPS is mandatory for GPS location)
- Cron access (for automation)
B. External APIs (Required)
1οΈβ£ Google Maps API
Enable:
- Maps JavaScript API
- Distance Matrix API
- Geocoding API
Used for:
- Distance calculation (KM)
- Location verification
C. Frontend Technologies
- HTML5
- CSS3
- JavaScript (Vanilla / jQuery)
- Bootstrap (recommended)
- Browser Geolocation API
2οΈβ£ Folder Structure (Core PHP Friendly)
khoz/
βββ admin/
β βββ dashboard.php
β βββ managers.php
β βββ expenses.php
β βββ attendance.php
β βββ approvals.php
β
βββ manager/
β βββ dashboard.php
β βββ staff.php
β βββ attendance.php
β βββ expenses.php
β
βββ marketing/
β βββ dashboard.php
β βββ attendance.php
β βββ expenses.php
β
βββ caller/
β βββ dashboard.php
β
βββ includes/
β βββ config.php
β βββ db.php
β βββ auth.php
β βββ header.php
β βββ footer.php
β βββ permissions.php
β
βββ api/
β βββ attendance.php
β βββ calculate-distance.php
β βββ expense.php
β βββ approval.php
β
βββ assets/
β βββ css/
β βββ js/
β βββ images/
β
βββ uploads/
βββ logs/
βββ index.php
3οΈβ£ Database Structure (MySQL)
1. Users Table
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
password VARCHAR(255),
role ENUM('admin','manager','caller','marketing'),
parent_id INT DEFAULT NULL,
manager_id INT DEFAULT NULL,
status TINYINT DEFAULT 1,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
2. Attendance Table
CREATE TABLE attendance (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
manager_id INT,
date DATE,
check_in_time DATETIME,
check_in_lat DECIMAL(10,8),
check_in_lng DECIMAL(11,8),
check_out_time DATETIME,
check_out_lat DECIMAL(10,8),
check_out_lng DECIMAL(11,8),
total_km DECIMAL(6,2),
status ENUM('present','absent') DEFAULT 'present',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
3. Marketing Expenses Table
CREATE TABLE marketing_expenses (
id INT AUTO_INCREMENT PRIMARY KEY,
attendance_id INT,
user_id INT,
manager_id INT,
date DATE,
total_km DECIMAL(6,2),
rate_per_km DECIMAL(5,2) DEFAULT 4.00,
amount DECIMAL(8,2),
status ENUM('pending','manager_approved','admin_approved','paid','rejected') DEFAULT 'pending',
manager_remark TEXT,
admin_remark TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
4. Activity Logs (Optional but Recommended)
CREATE TABLE activity_logs (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
action VARCHAR(255),
entity_type VARCHAR(50),
entity_id INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
4οΈβ£ Attendance Logic (PHP Flow)
Check-In (Start Day)
- Get GPS using JavaScript
- Send lat/lng to
api/attendance.php - Save check-in time & location
Check-Out (End Day)
- Capture GPS again
- Calculate distance
- Store KM
- Auto-create expense entry
5οΈβ£ Distance Calculation (PHP)
Using Google Distance Matrix API
$distance_km = $distance_meters / 1000;
$amount = $distance_km * 4;
Store both values in DB.
6οΈβ£ Permissions Handling (permissions.php)
function checkAccess($allowedRoles) {
if (!in_array($_SESSION['role'], $allowedRoles)) {
header("Location: /khoz/index.php");
exit;
}
}
Usage:
checkAccess(['marketing']);
7οΈβ£ Approval Flow (Backend)
| ActionWho | |
| Create attendance | Marketing |
| Auto-create expense | System |
| Approve | Manager |
| Final approve | Admin |
| Mark paid | Admin |
8οΈβ£ Security Must-Haves
- Password hashing (
password_hash) - CSRF tokens
- GPS permission enforcement
- Session-based auth
- SQL prepared statements
- HTTPS required for GPS
9οΈβ£ Cron Jobs (Optional)
- Auto mark absent
- Monthly expense summary
- Auto-lock old records
π Final Implementation Order (Recommended)
- Login & roles
- Manager β Marketing hierarchy
- Attendance check-in/out
- Distance calculation
- Auto expense generation
- Approval system
- Reports & export
β Final Result
You will have a production-ready, scalable system using pure PHP + MySQL, with:
- Online attendance
- GPS-based allowance
- Multi-level approval
- Fraud prevention
- Clean role separation
If you want next:
- πΉ Full attendance.php API code
- πΉ Google Maps API setup
- πΉ UI HTML + JS
- πΉ SQL optimization
- πΉ Security hardening
Just tell me what to build next π