Add ticket template system for quick ticket creation: - Created TemplateModel.php with full CRUD operations for templates - Added get_template.php API endpoint to fetch template data - Updated TicketController to load templates in create() method - Modified CreateTicketView.php to include template selector dropdown - Added loadTemplate() JavaScript function to populate form fields - Templates include: title, description, category, type, and default priority - Database already seeded with default templates (Hardware Failure, Software Installation, Network Issue, Maintenance Request) Users can now select from predefined templates when creating tickets, speeding up common ticket creation workflows. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* TemplateModel - Handles ticket template operations
|
|
*/
|
|
class TemplateModel {
|
|
private $conn;
|
|
|
|
public function __construct($conn) {
|
|
$this->conn = $conn;
|
|
}
|
|
|
|
/**
|
|
* Get all active templates
|
|
*
|
|
* @return array Array of template records
|
|
*/
|
|
public function getAllTemplates() {
|
|
$sql = "SELECT * FROM ticket_templates WHERE is_active = TRUE ORDER BY template_name";
|
|
$result = $this->conn->query($sql);
|
|
|
|
$templates = [];
|
|
while ($row = $result->fetch_assoc()) {
|
|
$templates[] = $row;
|
|
}
|
|
return $templates;
|
|
}
|
|
|
|
/**
|
|
* Get template by ID
|
|
*
|
|
* @param int $templateId Template ID
|
|
* @return array|null Template record or null if not found
|
|
*/
|
|
public function getTemplateById($templateId) {
|
|
$sql = "SELECT * FROM ticket_templates WHERE template_id = ? AND is_active = TRUE";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bind_param("i", $templateId);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
$template = $result->fetch_assoc();
|
|
$stmt->close();
|
|
return $template;
|
|
}
|
|
|
|
/**
|
|
* Create a new template
|
|
*
|
|
* @param array $data Template data
|
|
* @param int $createdBy User ID creating the template
|
|
* @return bool Success status
|
|
*/
|
|
public function createTemplate($data, $createdBy) {
|
|
$sql = "INSERT INTO ticket_templates (template_name, title_template, description_template,
|
|
category, type, default_priority, created_by)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bind_param("sssssii",
|
|
$data['template_name'],
|
|
$data['title_template'],
|
|
$data['description_template'],
|
|
$data['category'],
|
|
$data['type'],
|
|
$data['default_priority'],
|
|
$createdBy
|
|
);
|
|
|
|
$result = $stmt->execute();
|
|
$stmt->close();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Update an existing template
|
|
*
|
|
* @param int $templateId Template ID
|
|
* @param array $data Template data to update
|
|
* @return bool Success status
|
|
*/
|
|
public function updateTemplate($templateId, $data) {
|
|
$sql = "UPDATE ticket_templates SET
|
|
template_name = ?,
|
|
title_template = ?,
|
|
description_template = ?,
|
|
category = ?,
|
|
type = ?,
|
|
default_priority = ?
|
|
WHERE template_id = ?";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bind_param("ssssiii",
|
|
$data['template_name'],
|
|
$data['title_template'],
|
|
$data['description_template'],
|
|
$data['category'],
|
|
$data['type'],
|
|
$data['default_priority'],
|
|
$templateId
|
|
);
|
|
|
|
$result = $stmt->execute();
|
|
$stmt->close();
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* Deactivate a template (soft delete)
|
|
*
|
|
* @param int $templateId Template ID
|
|
* @return bool Success status
|
|
*/
|
|
public function deactivateTemplate($templateId) {
|
|
$sql = "UPDATE ticket_templates SET is_active = FALSE WHERE template_id = ?";
|
|
$stmt = $this->conn->prepare($sql);
|
|
$stmt->bind_param("i", $templateId);
|
|
|
|
$result = $stmt->execute();
|
|
$stmt->close();
|
|
return $result;
|
|
}
|
|
}
|