# OnlyOffice Integration - Quick Start

## ✅ Installation Complete!

OnlyOffice Document Server is now running and integrated with your M1 ERP File Manager.

## Access Points

### 1. Test Page
```
http://localhost/onlyoffice/test
```
View FTZ test files and open them in the editor.

### 2. OnlyOffice Server
```
http://localhost:8080/welcome/
```
Direct access to OnlyOffice Document Server welcome page.

## Test the Integration

### Step 1: Upload a Test File
1. Go to **File Manager**: http://localhost/files
2. Navigate to or create "FTZ" folder
3. Upload a Word/Excel/PowerPoint document

### Step 2: Open in Editor
1. Go to **Test Page**: http://localhost/onlyoffice/test
2. Find your uploaded file
3. Click **"Edit with OnlyOffice"**
4. Document opens in full-screen editor!

### Step 3: Edit and Save
1. Make changes to the document
2. Changes auto-save every few seconds
3. Close the editor tab
4. Your changes are saved back to the file manager

## Files Created

### Controllers
- `controllers/OnlyOfficeController.php` - Main integration logic

### Views
- `views/onlyoffice/test.php` - Test page with file listing
- `views/onlyoffice/editor.php` - Full-screen editor interface

### Routes (in public/index.php)
- `GET /onlyoffice/test` - Test page
- `GET /onlyoffice/editor/{fileId}` - Open editor
- `GET /onlyoffice/download/{fileId}` - File content for OnlyOffice
- `POST /onlyoffice/callback/{fileId}` - Save callback

### Documentation
- `docs/ONLYOFFICE_INTEGRATION.md` - Complete API documentation

### Test Files
- `uploads/files/ftz/test_document.txt` - Sample test file

## Supported File Types

✅ **Word:** .doc, .docx, .rtf, .txt, .odt
✅ **Excel:** .xls, .xlsx, .csv, .ods  
✅ **PowerPoint:** .ppt, .pptx, .odp

## How It Works

```
User clicks "Edit"
    ↓
Your ERP generates OnlyOffice config
    ↓
OnlyOffice fetches file from your ERP
    ↓
User edits in browser
    ↓
OnlyOffice auto-saves changes
    ↓
OnlyOffice sends edited file back to your ERP
    ↓
Your ERP saves the new version
```

## Docker Commands

```bash
# Check if running
docker ps | grep onlyoffice

# View logs
docker logs onlyoffice-document-server

# Restart
docker restart onlyoffice-document-server

# Stop
docker stop onlyoffice-document-server

# Start
docker start onlyoffice-document-server
```

## Next Steps

1. **Test the integration** - Upload and edit a document
2. **Add Edit button** to File Manager toolbar
3. **Enable versioning** for document history
4. **Configure for production** with JWT security

## Troubleshooting

**Can't access test page?**
- Make sure you're logged into the ERP
- Navigate to: http://localhost/onlyoffice/test

**Editor doesn't load?**
- Check OnlyOffice is running: `docker ps | grep onlyoffice`
- Check browser console for errors

**Changes not saving?**
- Check PHP error logs
- Ensure `uploads/files/` directory is writable (755 permissions)

## Full Documentation

See `docs/ONLYOFFICE_INTEGRATION.md` for:
- Complete API structure
- Production deployment guide
- Security configuration (JWT)
- Advanced features (co-authoring, track changes, watermarks)
- Integration with File Manager UI

---

**Ready to test!** Visit: http://localhost/onlyoffice/test
