query("DESCRIBE fish_types"); $columns = []; while ($row = $columns_result->fetch_assoc()) { $columns[] = $row['Field']; } // Determine which columns exist $id_col = in_array('fish_id', $columns) ? 'fish_id' : 'id'; $name_en_col = in_array('fish_name_english', $columns) ? 'fish_name_english' : (in_array('fish_name', $columns) ? 'fish_name' : 'name'); $name_ta_col = in_array('fish_name_tamil', $columns) ? 'fish_name_tamil' : (in_array('tamil_name', $columns) ? 'tamil_name' : null); $status_col = in_array('status', $columns) ? 'status' : null; $created_col = in_array('created_at', $columns) ? 'created_at' : null; // Handle Add Fish Type if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'add_fish') { $fish_name = trim($_POST['fish_name']); $fish_name_tamil = trim($_POST['fish_name_tamil'] ?? ''); if (empty($fish_name)) { $error = "Fish name is required"; } else { try { // Check duplicate $check_sql = "SELECT $id_col FROM fish_types WHERE $name_en_col = ?"; $stmt = $conn->prepare($check_sql); $stmt->bind_param("s", $fish_name); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { $error = "Fish type '$fish_name' already exists"; } else { // Build INSERT query based on available columns $insert_cols = [$name_en_col]; $insert_vals = [$fish_name]; $types = "s"; if ($name_ta_col && !empty($fish_name_tamil)) { $insert_cols[] = $name_ta_col; $insert_vals[] = $fish_name_tamil; $types .= "s"; } if ($status_col) { $insert_cols[] = $status_col; $insert_vals[] = 'active'; $types .= "s"; } if ($created_col) { $insert_cols[] = $created_col; $insert_vals[] = date('Y-m-d H:i:s'); $types .= "s"; } $cols_str = implode(', ', $insert_cols); $placeholders = implode(', ', array_fill(0, count($insert_cols), '?')); $sql = "INSERT INTO fish_types ($cols_str) VALUES ($placeholders)"; $stmt = $conn->prepare($sql); if ($stmt) { $stmt->bind_param($types, ...$insert_vals); if ($stmt->execute()) { logActivity($_SESSION['user_id'], 'CREATE', 'fish_types', "Created fish type: $fish_name"); $success = "Fish type '$fish_name' created successfully!"; } else { $error = "Failed to create fish type: " . $stmt->error; } } else { $error = "Database error: " . $conn->error; } } } catch (Exception $e) { $error = "Error: " . $e->getMessage(); } } } // Handle Toggle Status (only if status column exists) if ($status_col && isset($_GET['toggle'])) { $fish_id = intval($_GET['toggle']); try { $sql = "UPDATE fish_types SET $status_col = IF($status_col = 'active', 'inactive', 'active') WHERE $id_col = ?"; $stmt = $conn->prepare($sql); $stmt->bind_param("i", $fish_id); $stmt->execute(); logActivity($_SESSION['user_id'], 'UPDATE', 'fish_types', "Toggled fish type status (ID: $fish_id)"); $success = "Fish type status updated"; } catch (Exception $e) { $error = "Error: " . $e->getMessage(); } } // Get all fish types try { $select_cols = [$id_col, $name_en_col]; if ($name_ta_col) $select_cols[] = $name_ta_col; if ($status_col) $select_cols[] = $status_col; $cols_str = implode(', ', $select_cols); $fish_types = fetchAll("SELECT $cols_str FROM fish_types ORDER BY $name_en_col"); } catch (Exception $e) { $fish_types = []; $error = "Error loading fish types: " . $e->getMessage(); } $page_title = 'Manage Fish Types'; require_once __DIR__ . '/../includes/header.php'; ?>

🐟 Manage Fish Types

➕ Add New Fish Type

All Fish Types ()

Fish Name Status Actions

Active Inactive
🐟

No fish types yet

Add your first fish type using the form on the left

💡 Common Fish Types in Tamil Nadu

Here are some common fish types you can add:

'Tuna', 'tamil' => 'சூரை (Soorai)'], ['english' => 'Mackerel', 'tamil' => 'அயிலை (Ayilai)'], ['english' => 'Sardine', 'tamil' => 'மத்தி (Mathi)'], ['english' => 'Pomfret', 'tamil' => 'வாவல் (Vaaval)'], ['english' => 'King Fish', 'tamil' => 'நெய்மீன் (Neimeen)'], ['english' => 'Prawns', 'tamil' => 'இறால் (Iraal)'], ['english' => 'Crab', 'tamil' => 'நண்டு (Nandu)'], ['english' => 'Squid', 'tamil' => 'கணவாய் (Kanavai)'], ['english' => 'Anchovy', 'tamil' => 'நெத்திலி (Nethili)'], ['english' => 'Red Snapper', 'tamil' => 'சங்கரா (Sangara)'], ['english' => 'Seer Fish', 'tamil' => 'வஞ்சிரம் (Vanjiram)'], ['english' => 'Pomfret White', 'tamil' => 'வெள்ளை வாவல் (Vellai Vaaval)'], ]; foreach ($common_fish as $fish): ?>

ℹ️ Table Structure Detected

Columns found in your fish_types table:
ID Column:
Name Column:
Tamil Name Column:
Status Column:

ℹ️ Important Notes