πŸ“ž +91 9473426501 βœ‰ info@collegekhoz.com

Blog

National Scholarship Portal 2025

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

  1. PHP 8.x
  2. MySQL 5.7+ / 8.0
  3. Apache / Nginx
  4. SSL (HTTPS is mandatory for GPS location)
  5. Cron access (for automation)

B. External APIs (Required)

1️⃣ Google Maps API

Enable:

  1. Maps JavaScript API
  2. Distance Matrix API
  3. Geocoding API

Used for:

  1. Distance calculation (KM)
  2. Location verification

C. Frontend Technologies

  1. HTML5
  2. CSS3
  3. JavaScript (Vanilla / jQuery)
  4. Bootstrap (recommended)
  5. 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)

  1. Get GPS using JavaScript
  2. Send lat/lng to api/attendance.php
  3. Save check-in time & location

Check-Out (End Day)

  1. Capture GPS again
  2. Calculate distance
  3. Store KM
  4. 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 attendanceMarketing
Auto-create expenseSystem
ApproveManager
Final approveAdmin
Mark paidAdmin

8️⃣ Security Must-Haves

  1. Password hashing (password_hash)
  2. CSRF tokens
  3. GPS permission enforcement
  4. Session-based auth
  5. SQL prepared statements
  6. HTTPS required for GPS

9️⃣ Cron Jobs (Optional)

  1. Auto mark absent
  2. Monthly expense summary
  3. Auto-lock old records

πŸ”Ÿ Final Implementation Order (Recommended)

  1. Login & roles
  2. Manager β†’ Marketing hierarchy
  3. Attendance check-in/out
  4. Distance calculation
  5. Auto expense generation
  6. Approval system
  7. Reports & export

βœ… Final Result

You will have a production-ready, scalable system using pure PHP + MySQL, with:

  1. Online attendance
  2. GPS-based allowance
  3. Multi-level approval
  4. Fraud prevention
  5. Clean role separation

If you want next:

  1. πŸ”Ή Full attendance.php API code
  2. πŸ”Ή Google Maps API setup
  3. πŸ”Ή UI HTML + JS
  4. πŸ”Ή SQL optimization
  5. πŸ”Ή Security hardening

Just tell me what to build next πŸš€

Home Collages
Courses Login