Skip to content

ChadOhman/opensafetymap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

🚦 Edmonton Accident & Near Miss Reporting Platform

System Overview

CI/CD License: MIT GitHub release Contributors Open Issues Open PRs Docs Docs Setup Guide

CI/CD License: MIT GitHub release Contributors Open Issues Open PRs

A community-driven web application for reporting, tracking, and moderating traffic-related accidents and near misses in Edmonton.
Built with PHP + MySQL backend and a vanilla JS + Leaflet frontend.


✨ Features

πŸ‘₯ User System

  • OAuth login via Google, Apple, Mastodon, BlueSky
  • Random alias generator (adjective + adjective + noun) for privacy
  • User roles: user, moderator, admin
  • Privacy settings: public / logged-in only / private
  • Ban enforcement (login blocked for banned users)
  • User profile pages with reports and comments

πŸ“ Reporting

  • Report Accidents or Near Misses
  • Categories: Pedestrian, Cyclist, Motor Vehicle
  • Severity levels: Minor, Moderate, Severe
  • Upload photos (stored in S3)
  • Status workflow: Pending β†’ Approved/Rejected
  • Reports displayed on OpenStreetMap with clustering

πŸ’¬ Comments & Flags

  • Users can comment on reports
  • Flag system for inappropriate reports/comments
  • Moderators can dismiss or remove flagged content

πŸ›‘οΈ Moderation

  • Unified moderation dashboard:
    • Pending reports (approve/reject with notes)
    • Flagged content (dismiss/remove with notes)
    • Settings (require approval before publishing)
    • Analytics
    • Moderation log
  • Moderation log:
    • Logs all actions (approve/reject, ban/unban, flag resolve)
    • Immutable moderation notes
    • Filters: by action, keyword, date range

πŸ“Š Analytics

  • Total reports (approved, rejected, pending)
  • Approval vs rejection trends (weekly chart)
  • Average moderation resolution time
  • Moderator performance insights (extendable)

πŸ› οΈ Tech Stack

  • Backend: PHP 8+, MySQL 8, PDO
  • Frontend: HTML5, CSS3, JavaScript (ES6 Modules)
  • Maps: Leaflet.js + MarkerCluster
  • Auth: OAuth 2.0 (Google, Apple, Mastodon, BlueSky)
  • Storage: Amazon S3 (photo uploads)

πŸ“‚ Project Structure

accident-reports/
│── api/
β”‚   β”œβ”€β”€ auth/            # OAuth logins + logout
β”‚   β”œβ”€β”€ users/           # Profiles, roles, bans
β”‚   β”œβ”€β”€ reports/         # Submit, list, moderate
β”‚   β”œβ”€β”€ flags/           # Submit, list, resolve
β”‚   β”œβ”€β”€ admin/           # Settings, analytics
β”‚   └── moderation/      # Moderation log
│── db/
β”‚   β”œβ”€β”€ connect.php      # DB connection + session
β”‚   β”œβ”€β”€ auth_helper.php  # Auth + role checks
β”‚   └── api_response.php # Unified API response helper
│── public/
β”‚   β”œβ”€β”€ index.html       # Map + reporting form
β”‚   β”œβ”€β”€ login.html       # OAuth login
β”‚   β”œβ”€β”€ user_profile.html
β”‚   └── moderation_dashboard.html
│── assets/
β”‚   β”œβ”€β”€ css/style.css    # Shared styles
β”‚   └── js/              # JS modules
β”‚       β”œβ”€β”€ api.js
β”‚       β”œβ”€β”€ map.js
β”‚       β”œβ”€β”€ report_submission.js
β”‚       β”œβ”€β”€ user_profile.js
β”‚       β”œβ”€β”€ moderation.js
β”‚       └── auth.js
└── README.md

πŸ—ƒοΈ Database Schema (Simplified)

CREATE TABLE users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  username VARCHAR(255),
  oauth_provider VARCHAR(50),
  oauth_id VARCHAR(255),
  role ENUM('user','moderator','admin') DEFAULT 'user',
  status ENUM('active','banned') DEFAULT 'active',
  privacy ENUM('public','logged-in','private') DEFAULT 'public',
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE reports (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT,
  category_id INT,
  severity_id INT,
  incident_type_id INT,
  description TEXT,
  latitude DOUBLE,
  longitude DOUBLE,
  photo_url TEXT,
  status ENUM('pending','approved','rejected') DEFAULT 'pending',
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  resolved_at TIMESTAMP NULL,
  FOREIGN KEY (user_id) REFERENCES users(id)
);

CREATE TABLE comments (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT,
  report_id INT,
  content TEXT,
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE flags (
  id INT AUTO_INCREMENT PRIMARY KEY,
  user_id INT,
  report_id INT NULL,
  comment_id INT NULL,
  reason TEXT,
  status ENUM('pending','dismissed','removed') DEFAULT 'pending',
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE moderation_log (
  id INT AUTO_INCREMENT PRIMARY KEY,
  moderator_id INT,
  action_type VARCHAR(50),
  target_id INT,
  details TEXT,
  notes TEXT,
  timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE settings (
  id INT PRIMARY KEY,
  require_approval TINYINT(1) DEFAULT 1
);

CREATE TABLE categories (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE severity_levels (id INT PRIMARY KEY, name VARCHAR(50));
CREATE TABLE incident_types (id INT PRIMARY KEY, name VARCHAR(50));

πŸš€ Installation

1. Clone the repo

git clone https://github.com/ChadOhman/opensafetymap.git
cd accident-reports

2. Set up database

  • Import schema above into MySQL
  • Add reference data for categories, severity, incident types
  • Create initial admin user manually

3. Configure DB connection

Edit db/connect.php:

$dsn = "mysql:host=localhost;dbname=accidents;charset=utf8mb4";
$user = "your_mysql_user";
$pass = "your_mysql_pass";

4. Configure S3

  • Update report submission API to upload photos to your S3 bucket
  • Store photo_url in DB

5. Run locally

Use PHP’s built-in server:

php -S localhost:8000 -t public

Open http://localhost:8000.

6. Offline-friendly validation

When npm-based tooling is blocked by the network proxy, you can still run basic checks to avoid regressions:

python tools/html_checks.py index.html
python tools/a11y_checks.py index.html

These scripts verify document structure, labeling, and key accessibility affordances without downloading external packages.


πŸ”’ Roles & Permissions

  • User β†’ Submit reports, comment, flag content
  • Moderator β†’ Moderate reports & flags, add notes
  • Admin β†’ All moderator actions + manage settings, roles, bans

πŸ“Œ Roadmap

  • Moderator performance analytics (leaderboard)
  • Email notifications for approvals/rejections
  • Map heatmap visualization of reports
  • Export moderation logs to CSV/Excel

πŸ§‘β€πŸ’» Contributors

  • Backend: PHP/MySQL
  • Frontend: JS/Leaflet
  • Maintainer: Your Name

πŸ“œ License

MIT License.
Free to use, modify, and distribute.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published