# Hopepress Chapel Attendance Management System

## Project Structure

\`\`\`
hopepress-attendance/
├── api/                          # Backend PHP API
│   ├── config/
│   │   ├── database.php         # Database connection
│   │   └── cors.php             # CORS headers
│   ├── utils/
│   │   └── helpers.php          # Helper functions
│   ├── auth/                    # Authentication endpoints
│   │   ├── register.php
│   │   ├── verify.php
│   │   ├── complete-registration.php
│   │   ├── login.php
│   │   └── logout.php
│   ├── user/                    # User management endpoints
│   │   ├── profile.php
│   │   └── update.php
│   ├── services/                # Service management endpoints
│   │   ├── list.php
│   │   ├── active.php
│   │   ├── create.php
│   │   ├── update.php
│   │   └── delete.php
│   ├── attendance/              # Attendance endpoints
│   │   ├── clock-in.php
│   │   ├── clock-out.php
│   │   ├── history.php
│   │   └── status.php
│   ├── tickets/                 # Tickets endpoints
│   │   ├── list.php
│   │   ├── progress.php
│   │   └── redeem.php
│   ├── admin/                   # Admin endpoints
│   │   ├── dashboard.php
│   │   ├── users.php
│   │   └── reports.php
│   ├── .htaccess               # URL rewriting
│   └── index.php               # API router
├── database/
│   └── schema.sql              # Database schema
├── frontend/                    # Frontend files
│   ├── assets/
│   │   ├── css/
│   │   │   └── styles.css
│   │   ├── js/
│   │   │   ├── config.js
│   │   │   ├── home.js
│   │   │   ├── login.js
│   │   │   ├── register.js
│   │   │   ├── attendance.js
│   │   │   ├── services.js
│   │   │   └── tickets.js
│   │   └── images/
│   │       └── logo.png
│   ├── index.html              # Home page
│   ├── login.html              # Login page
│   ├── register.html           # Registration page
│   ├── attendance.html         # Attendance history page
│   ├── services.html           # Services page
│   └── tickets.html            # Tickets page
└── README.md
\`\`\`

## Setup Instructions

### Database Setup
1. Create a MySQL database named `hopepress_attendance`
2. Import the schema: `mysql -u root -p hopepress_attendance < database/schema.sql`
3. Update database credentials in `api/config/database.php`

### API Setup
1. Place the `api` folder in your web server directory (e.g., `htdocs/hopepress-attendance/api`)
2. Ensure mod_rewrite is enabled for Apache
3. Update the JWT secret key in `api/utils/helpers.php` for production
4. Update CORS settings in `api/config/cors.php` if needed

### Frontend Setup
1. Place the `frontend` folder in your web server directory
2. Update the API base URL in `frontend/assets/js/config.js` to match your API location
3. Serve the frontend files through a web server

### Creating the First Admin User
1. Register a new user through the registration page
2. Manually update the user's role in the database:
   \`\`\`sql
   UPDATE users SET role = 'admin' WHERE email = 'your-admin-email@example.com';
   \`\`\`

## API Endpoints

### Authentication
- `POST /auth/register` - Register new user (sends OTP)
- `POST /auth/verify` - Verify email with OTP
- `POST /auth/complete-registration` - Complete registration with user details
- `POST /auth/login` - User login
- `POST /auth/logout` - User logout

### User
- `GET /user/profile` - Get user profile
- `PUT /user/update` - Update user profile

### Services
- `GET /services/list` - Get all services
- `GET /services/active` - Get active service for today
- `POST /services/create` - Create new service (admin only)
- `PUT /services/update` - Update service (admin only)
- `DELETE /services/delete` - Delete service (admin only)

### Attendance
- `POST /attendance/clock-in` - Clock in to service (requires geolocation)
- `POST /attendance/clock-out` - Clock out from service (requires geolocation)
- `GET /attendance/history` - Get attendance history
- `GET /attendance/status` - Get current attendance status

### Tickets
- `GET /tickets/list` - Get user tickets
- `GET /tickets/progress` - Get ticket progress for reward-based services
- `POST /tickets/redeem` - Redeem ticket (admin only)

### Admin
- `GET /admin/dashboard` - Get dashboard statistics
- `GET /admin/users` - Get all users (admin only)
- `PUT /admin/users` - Update user role (admin only)
- `GET /admin/reports` - Generate reports (admin only)

## Features

### User Features
- Email-based registration with OTP verification
- Secure login with JWT authentication
- Profile management
- Geofence-based clock in/out for services
- Real-time attendance tracking
- Attendance history with filtering
- Ticket progress tracking for reward-based services
- QR code generation for earned tickets
- Service information and schedules

### Admin Features
- Dashboard with key statistics
- User management (view, search, update roles)
- Service management (create, update, delete)
- Ticket redemption via QR code scanning
- Comprehensive reporting:
  - General reports (overall statistics)
  - Individual user reports
  - Service-specific reports
- Activity logging

### Security Features
- JWT-based authentication
- Password hashing with bcrypt
- Email verification
- Role-based access control
- Geofence validation for attendance
- Admin activity logging

## Technologies

- **Backend**: Vanilla PHP with PDO
- **Frontend**: HTML5, CSS3, Vanilla JavaScript
- **Database**: MySQL
- **Authentication**: JWT tokens
- **QR Codes**: QRCode.js library

## Configuration

### Geofencing
Services have configurable geofence radius (default 100 meters). Users must be within this radius to clock in/out.

### Reward System
Services can be marked as reward-based with a configurable number of attendances required to earn a ticket.

### Email Configuration
Update the `sendEmail()` function in `api/utils/helpers.php` to integrate with your email service (PHPMailer, SendGrid, etc.).

## Support

For support, email support@hopepresschapel.org or use the help icon in the app.

## License

Copyright © 2025 The Hopepress Chapel. All rights reserved.
