Skip to content

Lancelcode/GreenScore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

261 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

GreenScore Logo

๐ŸŒฑ GreenScore

Sustainability Tracking & Certification Web Application

PHP MySQL Bootstrap PHPUnit Tests License

Empowering organisations to measure, track, and showcase their environmental impact โ€” with structured scoring, digital certificates, and community engagement.

๐Ÿš€ Getting Started ยท โœจ Features ยท ๐Ÿงช Tests ยท ๐Ÿ›ก๏ธ Security ยท ๐Ÿ—„๏ธ Database


๐Ÿ“Œ About the Project

GreenScore is a full-stack sustainability platform built with PHP and MySQL. Organisations complete a structured environmental assessment across 10 categories, earn one of 14 progressive badge levels, and receive official downloadable certificates โ€” Gold, Silver, Bronze, or Participation โ€” based on their cumulative performance.

The platform includes a community tip board, a user feedback system, a secure contribution flow for upgrading certificates, a comprehensive admin dashboard, dark mode, and a full toast notification system โ€” all built with a strong emphasis on security best practices.

๐ŸŽ“ Developed as part of the Graded Unit 2 Software Development assessment at Edinburgh College โ€” Academic Year 2024/2025.


โœจ Key Features

Feature Description
๐Ÿ” Authentication Registration, login, logout, password reset, session-based role management
๐Ÿงฎ Green Calculator 10-category assessment rated RED / AMBER / GREEN โ€” score out of 100
๐Ÿ… 14 Badge Levels Progressive badges from Green Starter to Champion of Sustainability
๐Ÿ“„ Certificates Gold / Silver / Bronze / Participation โ€” real submission date, company name, certificate ref number, print-to-PDF
๐Ÿ“œ Certificate History Responsive card layout โ€” colour-coded by award, score bar, filter by level, sort by date
๐Ÿ’ธ Buy Points Contribute to close a score gap and upgrade a certificate to Gold
๐Ÿ“Š My Impact Personal dashboard โ€” badge level, green answer count, contribution total, progress bar
๐Ÿ“ Community Board Paginated tip board with keyword search, character counter, create/edit/delete per user
๐Ÿ“ฌ Feedback System User submission with admin response panel and public visibility toggle
๐Ÿ‘ฅ Admin Dashboard Role/status management, user editing, feedback moderation
๐ŸŒ™ Dark Mode Full dark mode with localStorage persistence across page navigation
๐Ÿ”” Toast Notifications Dismissible floating toasts sitewide โ€” success, error, warning, info

๐Ÿ›ก๏ธ Security

Security was a core design priority throughout development:

Protection Implementation
Password hashing password_hash() with bcrypt โ€” auto-salted, unique per user
SQL injection Prepared statements with bound parameters across all 44 PHP files
CSRF protection Token generated once per session in init.php, validated on every state-changing form
Session fixation session_regenerate_id(true) immediately on login; periodic regeneration every 15 min
Idle timeout Session destroyed after 30 minutes of inactivity
Login rate limiting IP blocked after 5 failed attempts in 15 minutes โ€” recorded in login_attempts table
Password complexity Min 8 chars, uppercase + lowercase + number required, common passwords blocked
Cookie flags HttpOnly, SameSite=Strict on session cookie
Security headers X-Frame-Options: DENY, X-Content-Type-Options, Referrer-Policy, X-XSS-Protection, Permissions-Policy
Role-based access Admin routes return HTTP 403 if accessed without correct session role
Output sanitisation All user data escaped with htmlspecialchars() before rendering
.htaccess Blocks direct GET to includes/, blocks .sql/.env/.log files, custom 403/404 pages

Tech Stack

Layer Technology
Backend PHP 8.2
Database MySQL / MariaDB via XAMPP
Frontend HTML5, CSS3, JavaScript (ES6)
UI Framework Bootstrap 5.3
Icons Font Awesome 6.4
Testing PHPUnit 11.5 (via phar)
Dev Environment XAMPP, phpMyAdmin, PHPStorm

Database

Six tables with foreign key constraints and cascading deletes:

Table Purpose
new_users Accounts, roles (admin/user), statuses, company details
green_calculator_results Scores, award levels, badge data, donation records
community_tips User-submitted tips with ownership
feedback Messages, admin responses, public visibility flag
credit_cards Saved card details per user
login_attempts IP-based rate limiting records

The full schema with seed data is available at database/gradedunit.sql.


Project Structure

/
โ”œโ”€โ”€ index.php                    โ† Home page
โ”œโ”€โ”€ style.css                    โ† Global stylesheet (CSS variables, dark mode, responsive)
โ”œโ”€โ”€ .htaccess                    โ† Security rules, error routing
โ”œโ”€โ”€ 403.php / 404.php            โ† Custom error pages
โ”œโ”€โ”€ assets/
โ”‚   โ”œโ”€โ”€ favicon.svg
โ”‚   โ”œโ”€โ”€ images/                  โ† Backgrounds, 14 badge illustrations, partner logos
โ”‚   โ””โ”€โ”€ documents/               โ† Downloadable PDF guides
โ”œโ”€โ”€ includes/
โ”‚   โ”œโ”€โ”€ init.php                 โ† Session bootstrap, security headers, CSRF, BASE_URL
โ”‚   โ”œโ”€โ”€ connect_db.php           โ† Database connection
โ”‚   โ”œโ”€โ”€ nav.php                  โ† Navigation (active highlighting, dark mode toggle)
โ”‚   โ”œโ”€โ”€ footer.php               โ† Toast system, back-to-top, dark mode JS
โ”‚   โ”œโ”€โ”€ head.php                 โ† Favicon, theme-color, stylesheet links
โ”‚   โ”œโ”€โ”€ helpers.php              โ† isActive(), renderEditButton(), renderRoleStatusForms()
โ”‚   โ”œโ”€โ”€ login_tools.php          โ† validate() with password_verify
โ”‚   โ”œโ”€โ”€ login_action.php         โ† Login POST handler with rate limiting
โ”‚   โ””โ”€โ”€ modals.php               โ† Register/login modal components
โ”œโ”€โ”€ pages/
โ”‚   โ”œโ”€โ”€ auth/                    โ† login, logout, register, register_action, forgot_password
โ”‚   โ”œโ”€โ”€ admin/                   โ† admin_feedback, manage_users, edit_user, public_feedback, process_feedback_admin
โ”‚   โ”œโ”€โ”€ calculator/              โ† green_calculator, certificate_history, certificate_preview, buy_points
โ”‚   โ”œโ”€โ”€ community/               โ† community, post_tip, edit_tip, delete_tip, clear_tips
โ”‚   โ”œโ”€โ”€ user/                    โ† user_account, my_impact, view_cards, manage_credit_card
โ”‚   โ””โ”€โ”€ info/                    โ† about, partner, privacy, terms, green_resources, feedback, greenscore_copyright
โ”œโ”€โ”€ database/
โ”‚   โ””โ”€โ”€ gradedunit.sql           โ† Full schema with seed data
โ””โ”€โ”€ tests/
    โ”œโ”€โ”€ LoginTest.php
    โ”œโ”€โ”€ GreenCalculatorTest.php
    โ”œโ”€โ”€ CommunityTipsTest.php
    โ”œโ”€โ”€ PaymentTest.php
    โ””โ”€โ”€ fake_login_tools.php     โ† Session simulation helper for testing

Testing

42 tests โ€” 63 assertions โ€” all passing

Test Class What it covers
LoginTest password_verify() path, correct session keys, wrong password, unknown email, admin role
GreenCalculatorTest All 4 award thresholds by boundary value, all-green/amber/red scoring, shortfall and cost
CommunityTipsTest Message validation, trimming, HTML escaping, auth guard, ownership check, pagination
PaymentTest Cost from shortfall, clamping (min/max), formatting, float conversion, post-payment state

A fake_login_tools.php helper simulates authenticated session state for testing protected routes without a live database connection.

php phpunit.phar --testdox --colors=never

โš™๏ธ Installation

Prerequisites

  • XAMPP with Apache + MySQL
  • PHP 8.2+

1. Clone

git clone https://github.com/Lancelcode/Graded-Unit-2-webpage.git

2. XAMPP Setup

  • Start Apache and MySQL in the XAMPP control panel
  • Place the project folder in C:/xampp/htdocs/

3. Database

  • Open phpMyAdmin at http://localhost/phpmyadmin
  • Create a database named gradedunit
  • Import database/gradedunit.sql
  • Default credentials in includes/connect_db.php: host localhost, user root, password empty

4. Open

http://localhost/Graded-Unit-2-webpage/

Demo credentials

Role Email Password
Admin [email protected] (set in your DB)
User [email protected] (set in your DB)

Author

Djiby Sow Rebollo

GitHub

Edinburgh College โ€” Software Development Graded Unit 2 โ€” Academic Year 2024/2025


๐Ÿ“„ License

This project is licensed under the MIT License.


Built with ๐Ÿ’š to make sustainability measurable.

Releases

No releases published

Packages

 
 
 

Contributors