<?php
/////////////////// ALI'S CODE
if (isset($_SESSION["username_" . $dbname])) {
    $user = $_SESSION["username_" . $dbname];

    $getuser = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user`='$user'") or die(mysqli_error($conn));
    $guser = mysqli_fetch_array($getuser);
    $none = "style='display:none'";

    $permissionGroups = [
        'masters' => ['customer', 'supplier', 'originmaster', 'destination','account'],
        'transactions' => ['shipment', 'updcontainer', 'updrecv', 'upddelv','recp_ent'],
        'reports' => ['shiporiginrep', 'deststockrep','shipmentmultireg','recpreg','ledger'],
        'tools' => ['dashboard']
    ];
    foreach ($permissionGroups as $group => $fields) {
        $allEmpty = true;
        foreach ($fields as $field) {
            if (empty($guser[$field])) {
                $$field = $none; 
            } else {
                $allEmpty = false;
            }
        }
        if ($allEmpty) {
            $$group = $none;
        }
    }
}

////////////////////// SAHIL'S CODE
// if (isset($_SESSION["username_" . $dbname])) {
//     $user = $_SESSION["username_" . $dbname];

//     $getuser = mysqli_query($conn, "SELECT * FROM `passmain` WHERE `user`='$user'") or die(mysqli_error($conn));
//     $guser = mysqli_fetch_array($getuser);
//     $line = '';

//     $none = "style='display:none'";

//     ###################### EXPENESES ######################

//     $expensefields = [
//         'supplier',
//         'expense',
//         'expentry',
//         'expentryreg',
//         'datesummrep',
//         'monthcomprep'
//     ];

//     $allExpenseEmpty = true;

//     foreach ($expensefields as $expensefield) {
//         if (!isset($guser[$expensefield]) || $guser[$expensefield] === '') {
//             $$expensefield = $none;
//         } else {
//             $$expensefield = "";
//             $allExpenseEmpty = false;
//         }
//     }

//     if ($allExpenseEmpty) {
//         $mexpenses = $none;
//     }

//     ###################### ORDERS ######################

//     $orderfields = [
//         'osupplier',
//         'oexpense',
//         'stkentry',
//         'order',
//         'orderreg',
//         'ordersummrep'
//     ];

//     $allOrderEmpty = true;

//     foreach ($orderfields as $orderfield) {
//         if (!isset($guser[$orderfield]) || $guser[$orderfield] === '') {
//             $$orderfield = $none;
//         } else {
//             $$orderfield = "";
//             $allOrderEmpty = false;
//         }
//     }

//     if ($allOrderEmpty) {
//         $orders = $none;
//     }
  
//     ###################### PAYROLL ######################

//     $payrollfields = [
//         'offerletter',
//         'department',
//         'employee',
//         'attendance',
//         'monthlyattend',
//         'salaryproc',
//         'salarypd',
//         'salaryslip',
//         'salaryreg',
//         'salarysumm',
//         'kargpay',
//         'loan',
//         'loanstat'
//     ];

//     $allPayrollEmpty = true;

//     foreach ($payrollfields as $payrollfield) {
//         if (!isset($guser[$payrollfield]) || $guser[$payrollfield] === '') {
//             $$payrollfield = $none;
//         } else {
//             $$payrollfield = "";
//             $allPayrollEmpty = false;
//         }
//     }

//     if ($allPayrollEmpty) {
//         $payroll = $none;
//     }



// }
