Sliders Documentation

Sliders Controller Documentation

File: /controllers/sliders.php

Purpose: Manages website slider/banner content with image uploads and multi-language support

Last Updated: December 21, 2024

Total Functions: 4

Lines of Code: ~218

---

๐Ÿ“‹ Overview

The Sliders Controller is a content management module that handles website sliders and banner management. It provides comprehensive functionality for creating, editing, and managing promotional banners with:

Primary Functions

Related Controllers

---

๐Ÿ—„๏ธ Database Tables

Primary Tables (Direct Operations)

Table NamePurposeKey Columns
**sliders**Slider/banner storageid, title, titleEn, titleUrl, openTarget, mediaType, media, description, descriptionEn, position, isActive, sysDate, userid, isdel
### Supporting Tables

Table NamePurposeKey Columns
**youtubelink**Tutorial video linksyoutubelinkid, title, url
---

๐Ÿ”‘ Key Functions

1. Default Action - Add Slider Form

Location: Line 54

Purpose: Display slider creation form

Process Flow:

1. Check authentication (handled externally)

2. Display slider add form template

3. Load form validation scripts

Template: slidersview/add.html

---

2. add() - Create New Slider

Location: Line 151

Purpose: Process new slider creation with media upload

Function Signature:

function add() {
    $title = $_POST['title'];              // Arabic title
    $titleEn = $_POST['titleEn'];          // English title
    $titleUrl = $_POST['titleUrl'];        // Link URL
    $openTarget = $_POST['openTarget'];    // Link target (_blank, _self)
    $mediaType = $_POST['mediaType'];      // Media type (0=image)
    $content = $_POST['content'];          // Arabic description
    $contentEn = $_POST['contentEn'];      // English description
    $position = $_POST['position'];        // Display position
    $isActive = $_POST['isActive'];        // Active status
}

Process Flow:

1. Extract POST data for slider fields

2. Upload media file using uploadnew('media', False, 0, 0, 'sliders')

3. Create RedBeanPHP record with all fields

4. Set system date and user ID

5. Save to database and return ID

RedBean Implementation:

$rdispense = R::dispense('sliders');
$rdispense->title = $title;
$rdispense->titleEn = $titleEn;
$rdispense->titleUrl = $titleUrl;
$rdispense->openTarget = $openTarget;
$rdispense->mediaType = 0;  // Fixed as image type
$rdispense->media = $media;
$rdispense->description = $content;
$rdispense->descriptionEn = $contentEn;
$rdispense->position = $position;
$rdispense->isActive = $isActive;
$rdispense->sysDate = date("Y-m-d H:i:s");
$rdispense->userid = $_SESSION['userid'];
$rdispense->isdel = 0;
$id = R::store($rdispense);

---

3. show - Display Slider Listings

Location: Line 75

Purpose: Show all active sliders with management options

Process Flow:

1. Query all sliders with isdel = 0

2. Load YouTube tutorial links

3. Assign data to template

4. Display slider listing with edit/delete options

Query:

$showData = R::findAll('sliders', 'isdel = 0');
$smarty->assign('showData', $showData);

Template: slidersview/show.html

---

4. update() - Edit Existing Slider

Location: Line 181

Purpose: Update slider content and optionally replace media

Function Signature:

function update() {
    $id = $_POST['id'];                    // Slider ID to update
    // ... same fields as add() function
    $media = uploadupdate('media', 'mediaurl', False, 0, 0, 'sliders');
}

Process Flow:

1. Extract POST data including slider ID

2. Handle media update using uploadupdate() - keeps existing if no new upload

3. Load existing record via RedBean

4. Update all fields with new values

5. Save updated record

Media Update Logic:

// uploadupdate() handles:
// - New file upload if provided
// - Keeps existing file if no new upload
// - Handles file replacement and cleanup
$media = uploadupdate('media', 'mediaurl', False, 0, 0, 'sliders');

---

5. deleteFinaly() - Permanent Deletion

Location: Line 210

Purpose: Permanently delete slider with file cleanup

Function Signature:

function deleteFinaly($id) {
    $rtrash = R::load('sliders', $id);
    if (file_exists('../upload/sliders/' . $rtrash->media)) {
        chmod('../upload/sliders/' . $rtrash->media, 0777);
        unlink('../upload/sliders/' . $rtrash->media);
    }
    R::trash($rtrash);
}

Process Flow:

1. Load slider record by ID

2. Check if media file exists

3. Set file permissions to 0777

4. Delete physical media file

5. Remove database record completely

---

๐Ÿ”„ Workflows

Workflow 1: Slider Creation Process

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Create New Slider
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Display Add Form
- Load slider creation template
- Initialize form validation
- Set up media upload fields
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Process Form Submission
- Extract all POST fields
- Validate required fields
- Process media upload
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Execute add() Function
- Upload media to /upload/sliders/
- Create RedBean slider record
- Set system metadata (date, user)
- Save to database
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Handle Response
- AJAX: Return JSON success/error
- Standard: Redirect to success page
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Workflow 2: Slider Update Process

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
START: Edit Existing Slider
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
1Load Edit Form
- Load slider by ID
- Populate form with existing data
- Display current media
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
2Process Update
- Handle media replacement (optional)
- Extract updated form fields
- Validate changes
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
3Execute update() Function
- Use uploadupdate() for smart media handling
- Load existing RedBean record
- Update all modified fields
- Save changes to database
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
โ–ผ
โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
4Cleanup and Redirect
- Remove old media if replaced
- Return success/error response
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

---

๐ŸŒ URL Routes & Actions

URL ParameterFunction CalledDescription
`do=` (empty)DefaultDisplay slider creation form
`do=add``add()`Process new slider creation
`do=show`Display listingShow all active sliders with management
`do=edit`Edit formDisplay slider edit form with existing data
`do=update``update()`Process slider modifications
`do=deleteFinaly``deleteFinaly()`Permanently delete slider and files
`do=sucess`Success pageDisplay operation success message
`do=error`Error pageDisplay operation error message
### Required Parameters by Action

Add Slider (do=add):

Edit Slider (do=edit):

Update Slider (do=update):

Delete Slider (do=deleteFinaly):

---

๐Ÿงฎ Calculation Methods

Media File Handling

// New upload (add function)
$media = uploadnew('media', False, 0, 0, 'sliders');
// Parameters: field_name, resize, width, height, folder

// Update upload (preserves existing if no new file)
$media = uploadupdate('media', 'mediaurl', False, 0, 0, 'sliders');
// Parameters: field_name, current_file_field, resize, width, height, folder

File Cleanup on Deletion

// Safe file deletion with permission handling
if (file_exists('../upload/sliders/' . $rtrash->media)) {
    chmod('../upload/sliders/' . $rtrash->media, 0777);  // Ensure deletable
    unlink('../upload/sliders/' . $rtrash->media);       // Remove file
}

AJAX Response Handling

// Success response
$data = array(
    'status' => 1, 
    'message' => 'ุชู…ุช ุงู„ุนู…ู„ูŠู‡ ุจู†ุฌุงุญ',     // Arabic message
    'message_en' => 'Success'            // English message
);
echo json_encode($data);

// Error response  
$data = array(
    'status' => 2, 
    'message' => 'ุญุฏุซ ุฎุทุฃ',              // Arabic error
    'message_en' => 'Error'             // English error
);
echo json_encode($data);

---

๐Ÿ”’ Security & Permissions

Authentication

File Upload Security

// Upload function provides security:
// - File type validation
// - Size restrictions  
// - Path traversal prevention
// - Sanitized filenames
uploadnew('media', False, 0, 0, 'sliders');

Input Sanitization

CURL/External Integration Support

// Supports external system integration
if (isset($_POST['curlpost']) && $_POST['curlpost'] == 1) {
    // Handle AJAX/CURL requests differently
    // Return JSON instead of redirects
}

---

๐Ÿ“Š Performance Considerations

File Storage Optimization

1. Media Organization:

- Files stored in /upload/sliders/ directory

- Unique filenames prevent conflicts

- No image resizing (False parameter) - consider for large files

2. Database Efficiency:

- RedBeanPHP provides ORM layer

- Simple queries for small slider datasets

- Consider pagination for large slider collections

3. Memory Management:

- File uploads may require adequate memory limits

- Large image files impact performance

Known Performance Issues

// No pagination in show() function
$showData = R::findAll('sliders', 'isdel = 0');
// May become slow with hundreds of sliders

// Consider implementing:
$showData = R::findAll('sliders', 'isdel = 0 ORDER BY position LIMIT 50');

---

๐Ÿ› Common Issues & Troubleshooting

1. File Upload Failures

Issue: Media files not uploading properly

Cause: Directory permissions or upload size limits

Debug:

// Check upload directory permissions
if (!is_writable('../upload/sliders/')) {
    chmod('../upload/sliders/', 0755);
}

// Check upload size in php.ini
ini_get('upload_max_filesize');
ini_get('post_max_size');

2. Media Files Not Deleting

Issue: File cleanup fails during deletion

Cause: File permissions or path issues

Fix:

// Debug file deletion
$file_path = '../upload/sliders/' . $rtrash->media;
if (file_exists($file_path)) {
    echo "File exists: " . $file_path;
    if (!is_writable($file_path)) {
        echo "File not writable";
        chmod($file_path, 0777);
    }
}

3. AJAX Response Issues

Issue: AJAX requests not returning proper JSON

Cause: Mixed output or header issues

Fix:

// Ensure clean JSON output
header('Content-Type: application/json');
// Avoid any echo/print before JSON output

4. Multi-language Display Problems

Issue: Arabic/English content not displaying correctly

Cause: Character encoding or template issues

Fix:

// Ensure UTF-8 encoding
header('Content-Type: text/html; charset=UTF-8');
// Check database charset is utf8mb4

---

๐Ÿงช Testing Scenarios

Test Case 1: Basic Slider Creation

1. Access slider add form
2. Fill all required fields (title, titleEn, content, etc.)
3. Upload image file
4. Set position and active status
5. Submit form and verify database entry
6. Check file exists in /upload/sliders/

Test Case 2: Slider Update with Media

1. Edit existing slider
2. Change title and description
3. Upload new media file
4. Verify old file is cleaned up
5. Check updated data in database

Test Case 3: AJAX Integration

1. Submit slider form with curlpost=1
2. Verify JSON response format
3. Test both success and error responses
4. Confirm no redirect occurs

Test Case 4: File Cleanup on Deletion

1. Create slider with media file
2. Note uploaded filename
3. Delete slider permanently
4. Verify database record removed
5. Confirm media file deleted from filesystem

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When media handling changes occur