๐Ÿ“š ERP Documentation Viewer

Beautiful, colorful documentation for your ERP system

Contact Us Controller Documentation

File: /controllers/contactusController.php

Purpose: Manages customer contact form submissions with administrative response tracking and AJAX functionality

Last Updated: December 20, 2024

Total Functions: 4

Lines of Code: ~219

---

๐Ÿ“‹ Overview

The Contact Us Controller manages customer inquiries and contact form submissions. It provides administrative functionality to view, respond to, and track contact form messages with user management and status tracking capabilities.

Primary Functions

---

๐Ÿ—„๏ธ Database Tables

Table NamePurposeKey Columns
**contactus**Contact messagesid, clientid, name, mobile, email, subject, message, isRead, sysDate, userreadid, isdel
**user**System usersuserid, employeename
---

๐Ÿ”‘ Key Functions

1. Default Action - Display Contact Messages

Location: Lines 7-10

Purpose: Show contact form management interface

2. details - View Message Details

Location: Lines 11-23

Purpose: View and mark contact message as read

Process Flow:

1. Load message by ID

2. Mark as read and assign to current user

3. Update read status and date

4. Display message details with user information

3. showajax - AJAX DataTable Interface

Location: Lines 67-194

Purpose: Provide paginated, searchable contact message interface

Features:

Filter Parameters:

$start_date = $_POST['start_date'];
$end_date   = $_POST['end_date'];
$isdel      = $_POST['isdel'];        // Deleted status
$isRead     = $_POST['isRead'];       // Read status  
$id         = $_POST['id'];           // Specific message ID
$clientid   = $_POST['clientid'];     // Client filter
$userreadid = $_POST['userreadid'];   // User who read filter

DataTable Response:

$output = array(
    "draw" => intval($_POST["draw"]),
    "recordsTotal" => intval($apps),
    "recordsFiltered" => $totals,
    "data" => array()
);

4. removecontroller - Soft Delete Message

Location: Lines 199-214

Purpose: Mark message as deleted (soft delete)

Process Flow:

1. Load message by ID

2. Set deletion flag and metadata

3. Record deletion user and timestamp

4. Return success/failure status

---

๐ŸŒ URL Routes & Actions

URL ParameterFunctionDescription
`do=` (empty)DefaultShow contact messages interface
`do=details`View detailsView specific message and mark as read
`do=getselectjoin`AJAX helperGeneric select lookup functionality
`do=showajax`AJAX dataDataTable data source
`do=removecontroller`DeleteSoft delete message
### DataTable Parameters

---

๐Ÿงฎ Query Logic

Advanced Search Query Building

$searchQuery = " ";

// Date range filtering
if($start_date != '' && $end_date != ''){
   $searchQuery .='and contactus.sysDate >= "' . $start_date . '" and contactus.sysDate <= "' . $end_date . '" ';
}

// Status filtering
if($isRead == 1){
   $searchQuery .= " and contactus.isRead > 0 "; 
}else{
   $searchQuery .= " and contactus.isRead = 0 "; 
}

// Multi-column search
if (isset($_POST['search']['value']) && $_POST['search']['value'] != "") {
    $searchQuery .= "and ( contactus.id LIKE '%" . $_POST["search"]["value"] . "%' 
                    OR contactus.name LIKE '%" . $_POST["search"]["value"] . "%'
                    OR contactus.email LIKE '%" . $_POST["search"]["value"] . "%'
                    OR contactus.subject LIKE '%" . $_POST["search"]["value"] . "%'
        )";
}

Join Query for User Information

SELECT contactus.*, user.employeename  
FROM `contactus` 
LEFT JOIN user ON contactus.userreadid = user.userid
WHERE 1 {searchQuery}

---

๐Ÿ”’ Security & Performance

Input Validation

Performance Considerations

Required Indexes

CREATE INDEX idx_contactus_date ON contactus(sysDate);
CREATE INDEX idx_contactus_status ON contactus(isRead, isdel);
CREATE INDEX idx_contactus_user ON contactus(userreadid);

---

๐Ÿ“Š Status Management

Message Status Types

Client Type Classification

Display Logic

// Client type display
if($row["clientid"] < 1){
   $clientid = 'ุฒุงุฆุฑ';  // Visitor
}else{
   $clientid = 'ุนู…ูŠู„';  // Client
}

// Read status display
if($row["isRead"] < 1){
   $isRead = 'ุบูŠุฑ ู…ู‚ุฑูˆุกุฉ';  // Unread
}else{
   $isRead = 'ู…ู‚ุฑูˆุกุฉ';      // Read
}

---

๐Ÿ“š Related Documentation

---

Documented By: AI Assistant

Review Status: โœ… Complete

Next Review: When major changes occur

โ†‘