- Added `users_permissions` table for managing user permissions. - Created `PermissionRepository` for handling permission logic. - Refactored `controls\Users::permissions()` to utilize the new database structure. - Introduced AJAX endpoint for saving user permissions. - Enhanced user management UI with permission checkboxes. - Added vacation management template for handling employee absences. - Implemented tests for `PermissionRepository`.
4.5 KiB
4.5 KiB
CLAUDE.md
Obecna wersja PHP na serwerze to 7.4 i należy to uwzględnij podczas pisania kodu.
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
CRM PRO is a Polish-language CRM application for task/project management, client management, finances, and work time tracking. Built with PHP + MySQL, Bootstrap, jQuery, and PHP templating.
Running the Application
- Web entry point:
index.php— routes via?module=<module>&action=<action>query params - AJAX endpoint:
ajax.php - REST API:
api.php - Background jobs:
cron.php(email import, recursive tasks, reminders) - Tests:
php tests/run.php(custom lightweight test runner, no PHPUnit) - SCSS: compiled via VS Code Live Sass Compile extension
Architecture
Layered structure with ongoing DDD migration
autoload/
├── Controllers/ # NEW: PSR-4 namespaced, camelCase methods
├── controls/ # LEGACY: snake_case methods, being gradually replaced
├── factory/ # Data access + business logic (legacy, being replaced by Domain)
├── Domain/ # NEW: Repository pattern, single-responsibility classes
│ ├── Tasks/ # WorkTimeRepository, TaskAttachmentRepository, MailToTaskImporter
│ ├── Crm/ # ClientRepository
│ ├── Finances/ # FinanceRepository
│ └── Users/ # UserRepository
├── view/ # View rendering layer
├── class.S.php # Global static utility (sessions, request params, email, hashing)
├── class.Tpl.php # Template engine: Tpl::view('path', $data)
├── class.DbModel.php # Simple ActiveRecord wrapper
└── class.Html.php # HTML form helper components
templates/ # PHP templates organized by module
templates_user/ # Custom user template overrides
Routing (controls\Site::route())
- Takes
moduleandactionGET params - Tries
\Controllers\{Module}Controller::{camelCaseAction}()first - Falls back to
\controls\{Module}::{snake_case_action}()
Autoloading
Custom spl_autoload_register in index.php: maps Namespace\Class → autoload/Namespace/Class.php, falling back to autoload/Namespace/class.Class.php.
Database access
- Medoo (
$mdbglobal) — primary query builder for SELECT/INSERT/UPDATE/DELETE - RedBean (
\R) — ORM used for some entity operations - Both configured in
index.phpfromconfig.phpcredentials
Key globals
$mdb— Medoo database instance$user— current session user array (\S::get_session('user'))$settings— merged app settings fromconfig.php+ DBsettingstable\S::get('param')— safe request parameter access
Refactoring Status (see REFACTORING_PLAN.md)
- Stage 1 (DONE): Tasks/WorkTime migrated to
Domain\Tasks\WorkTimeRepository - Stage 2 (IN PROGRESS): Controller standardization —
TasksControllerpartially migrated - Stage 3 (DONE): UI cleanup for work time billing
- Stage 4 (NEXT): Finance domain extraction
- Stage 5 (NEXT): View layer standardization
Migration rules
- No big-bang rewrites — one functional area per commit
- New code goes in
Domain/(repositories) andControllers/(camelCase) - Legacy
controls/andfactory/kept as adapters until full migration - Every migrated method must have at least one test in
tests/
Coding Conventions
- New controllers:
Controllers\{Module}Controllerwith camelCase methods - New domain code:
Domain\{Module}\{Name}Repositorywith constructor-injected$mdb - Legacy code:
controls\{Module}andfactory\{Module}with snake_case methods - Templates: rendered via
\Tpl::view('module/template', $data_array), XSS protection via\Tpl::secureHTML() - UI language: Polish (labels, comments, database content)
- File naming: new classes
ClassName.php, legacy classesclass.ClassName.php
Key Database Tables
tasks,tasks_work,tasks_attachments,task_user,task_action— task managementcrm_client— client recordsfinance_operations,finance_categories— financesusers,users_permissions— auth and RBACtasks_filtrs— saved user filters
Authentication
- Email + password with PHP sessions, IP validation, cookie-based remember-me
- Permission checks via
\controls\Users::permissions($user_id, $module) - Admin (user ID 1) can impersonate other users