moto sands for me
1,450.00 omr
<?php
include_once "settings.php"; // Ensure this file sets up $connessione (database connection)
//include 'ar.php';
if(isset($_GET["accessCat"])) $_SESSION["ad"]=$_GET["accessCat"]; //for the cntrol to dsply ads && (HIDE) not to display the cars brands logos
$bId = htmlspecialchars($_GET['bId'] ?? $_GET['bId']);
// Check if the 'accessCat' GET parameter is set
$accessCat = isset($_GET['accessCat']) ? $_GET['accessCat'] : '';
// Define available categories and their fields
$categories = $_SESSION['translations']['category'];
// Process form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$category = $connessione->real_escape_string($_POST['accessCat'] ?? $_GET['accessCat']);
$title = $connessione->real_escape_string($_POST['title'] ?? '');
$berid = $connessione->real_escape_string($_POST['berid'] ?? '');
$hetef = $connessione->real_escape_string($_POST['hetef'] ?? '');
$country = $connessione->real_escape_string($_POST['country'] ?? '');
$location_city = $connessione->real_escape_string($_POST['location_city'] ?? '');
$price = $connessione->real_escape_string($_POST['price'] ?? '');
$el3omla = $connessione->real_escape_string($_POST['el3omla'] ?? '');
$description = $connessione->real_escape_string($_POST['description'] ?? '');
$quantity = $connessione->real_escape_string($_POST['quantity'] ?? '');
$yearModel = $connessione->real_escape_string($_POST['yearModel'] ?? $_GET['year']);
$views = intval($_POST['views'] ?? 0);
//$attributes = $connessione->real_escape_string($_POST['attributes'] ?? '');
// Collect prod attributes data with default values
$attributes__ = [
'brand' => $_GET['brand'] ?? '',
'year' => $yearModel ?? '',
'regional_specifications' => $_POST['property3'] ?? '',
'odometer' => $_POST['property4'] ?? '',
'cylinders' => $_POST['property5'] ?? '',
'transmission' => $_POST['property6'] ?? '',
'keys' => $_POST['property7'] ?? '',
'full_options' => $_POST['property8'] ?? '',
'fuel' => $_POST['property9'] ?? '',
'wheel_drive' => $_POST['property10'] ?? '',
'exterior_color' => $_POST['property11'] ?? '',
'interior_color' => $_POST['property12'] ?? '',
'maintenance_report' => $_POST['property13'] ?? '',
'car_status' => $_POST['property17'] ?? ''
];
// Initialize an array to hold form data
$formData = [];
$formHtml = isset($_POST['form_html']) ? $_POST['form_html'] : '';
// Check if 'form_html' is set and is an array
if (isset($_POST['form_html']) && is_array($_POST['form_html'])) {
foreach ($_POST['form_html'] as $key => $value) {
// Sanitize each value
$formData[$key] = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
} else {
echo 'Error: form_html is not set or not an array.';
}
// Output the sanitized form data
foreach ($formData as $key => $value) {
echo htmlspecialchars($key) . ': ' . htmlspecialchars($value) . '<br>';
}
// Build the JSON object for the attributes field
$attributes = [
'form_html' => $formHtml,
'data' => $formData
];
// Convert the attributes array to a JSON string
$attributesJson = json_encode($attributes);
// Sanitize the JSON string for safe insertion
$attributes = $connessione->real_escape_string($attributesJson);
//$attributes = $connessione->real_escape_string(json_encode($attributes));
$delivery_available = isset($_POST['delivery_available']) ? 1 : 0;
$negotiable_price = isset($_POST['negotiable_price']) ? 1 : 0;
$status = $connessione->real_escape_string($_POST['status'] ?? '');
$collector = $connessione->real_escape_string($_POST['collector'] ?? '');
// Handle file uploads
$images = [];
if (isset($_FILES['images']) && !empty($_FILES['images']['name'][0])) {
$uploadDir = 'uploads/';
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0755, true);
}
foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {
$fileName = basename($_FILES['images']['name'][$key]);
$uploadFile = $uploadDir . $fileName;
if (move_uploaded_file($tmp_name, $uploadFile)) {
$images[] = $uploadFile;
}
}
}
$imagesList = implode(',', $images);
try {
$sql = mysqli_query($connessione, "INSERT INTO `bathae3i` (
`idBathae3i`,
`images`,
`category`,
`title`,
`berid`,
`hetef`,
`country`,
`location_city`,
`price`,
`el3omla`,
`description`,
`quantity`,
`chronoBathae3`,
`views`,
`attributes`,
`delivery_available`,
`negotiable_price`,
`status`,
`collector`
) VALUES (
NULL, '$imagesList', '$category', '$title', '$berid', '$hetef', '$country',
'$location_city', '$price', '$el3omla', '$description', '$quantity',
'".time()."', $views, '$attributes', $delivery_available, $negotiable_price,
'$status', '$collector'
)");
if (!$sql) {
die('Error: ' . htmlspecialchars($connessione->error));
}
} catch(Exception $e) {
echo "Exception: " . $e->getMessage();
}
}
// Retrieve records from the database
$sql = "SELECT * FROM `bathae3i` WHERE idBathae3i = '" . $bId . "'";
$result = $connessione->query($sql);
?>
<!DOCTYPE html>
<html <?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"lang=ar dir=rtl"; else echo"lang=en dir=ltr"; ?>>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bathae3i Management</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css__">
<style>
body {
<?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"lang=ar dir=rtl"; else echo"lang=en dir=ltr"; ?>
background-color: #f8f9fa;
font-family: Arial, sans-serif;
}
.container {
max-width: 1200px;
margin: 20px auto;
padding: 20px;
background-color: #ffffff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.form-control {
display: block;
width: 100%;
height: calc(1.5em + .75rem + 2px);
padding: .375rem .75rem;
margin-top: 3px;
font-size: 1rem;
font-weight: 400;
line-height: 1.5;
color: #495057;
background-color: #fff;
background-clip: padding-box;
border: 1px solid #ced4da;
border-radius: .25rem;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.btn {
display: inline-block;
font-weight: 400;
color: #212529;
text-align: center;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: transparent;
border: 1px solid transparent;
padding: .375rem .75rem;
font-size: 1rem;
line-height: 1.5;
border-radius: .25rem;
transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.btn-primary {
color: #fff;
background-color: #007bff;
border-color: #007bff;
}
h1 {
margin-bottom: 20px;
}
form {
margin-bottom: 30px;
}
.form-group {
margin-bottom: 15px;
}
.form-control, .form-check-input {
border-radius: 4px;
}
.custom-file-input {
display: none;
}
.custom-file-upload {
border: 2px solid #007bff;
border-radius: 8px;
display: inline-block;
padding: 12px 24px;
cursor: pointer;
background: linear-gradient(135deg, #007bff 0%, #00d2ff 100%);
color: #ffffff;
text-align: center;
font-weight: bold;
font-size: 16px;
transition: all 0.3s ease;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
position: relative;
}
.custom-file-upload:hover {
background: linear-gradient(135deg, #00d2ff 0%, #007bff 100%);
color: #f0f0f0;
transform: scale(1.05);
}
.custom-file-upload:before {
content: '???? ';
position: absolute;
<?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"right: 0px;"; else echo"left: 0px;"; ?>
top: 40%;
transform: translateY(-50%);
font-size: 18px;
}
.custom-file-input {
display: none;
}
.image-preview {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
}
.image-preview img {
max-width: 100px;
margin-right: 5px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
.image-preview {
display: flex;
flex-wrap: wrap;
margin-top: 10px;
border: 2px dashed #007bff;
border-radius: 8px;
padding: 10px;
background-color: #f8f9fa;
min-height: 120px;
position: relative;
overflow: auto;
}
.image-preview .placeholder {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: #007bff;
font-size: 18px;
font-weight: bold;
text-align: center;
pointer-events: none;
}
.image-preview img {
max-width: 100px;
margin: 5px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
table {
width: 100%;
border-collapse: collapse;
}
table th, table td {
border: 1px solid #dee2e6;
padding: 12px;
text-align: left;
}
table th {
background-color: #007bff;
color: #ffffff;
}
table td {
background-color: #ffffff;
}
.attributes-list {
white-space: pre-wrap; /* Preserve whitespace for line breaks */
}
.details-list {
list-style-type: none;
padding: 0;
margin: 0;
}
.details-list li:nth-child(even) {
background-color: #f9f9f9;
}
.details-list li {
padding: 10px;
border-bottom: 1px solid #eee;
}
.details-container {
background-color: #fff;
border: 1px solid #ddd;
padding: 20px;
margin-bottom: 20px;
font-family: Arial, sans-serif;
width: 100%;
margin: 0 auto;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
._vkey{
<?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"margin-left: 40px;"; else echo"margin-right: 40px;"; ?>
}
</style>
</head>
<body>
<div class="container">
<h1>Insert New Record</h1>
<form method="post" action="?accessCat=<?php echo $_GET['accessCat']; ?>&brand=<?php echo $_GET['brand']; ?>&year=<?php echo $_GET['year']; ?>" enctype="multipart/form-data">
<!--div class="form-group">
<label for="category">Category:</label>
<input type="text" id="category" name="accessCat" class="form-control" required>
</div -->
<div class="form-group">
<label for="images" class="custom-file-upload">
<span><?php echo $_SESSION["imageUpload"]; ?></span>
</label>
<input type="file" id="images" name="images[]" class="custom-file-input" accept="image/*" multiple>
<div class="image-preview" id="image-preview">
<div class="placeholder"><?php echo $_SESSION["imagesselected"]; ?></div>
</div>
</div>
<div class="form-group">
<label for="title">Title:</label>
<input type="text" id="title" name="title" class="form-control" required>
</div>
<?php if($_GET["accessCat"]=="cars")include_once"_carsSpecificities.php"; ?>
<?php //include_once"_vpcategoriesForms.php";
// Function to generate form fields
function generateFormFields($fields) {
$formHtml = '';
foreach ($fields as $field => $label) {
if (is_array($label)) { // Check if the field has subvalues
$formHtml .= '<label for="' . htmlspecialchars($field) . '">' . htmlspecialchars($label['type']) . ':</label>';
$formHtml .= '<select id="' . htmlspecialchars($field) . '" name="' . htmlspecialchars($field) . '" class="form-control">';
foreach ($label as $subValue => $subLabel) {
if ($subValue !== 'type') { // Skip the 'type' key
$formHtml .= '<option value="' . htmlspecialchars($subValue) . '">' . htmlspecialchars($subLabel) . '</option>';
}
}
$formHtml .= '</select><br><br>';
} else {
$formHtml .= '<label for="' . htmlspecialchars($field) . '">' . htmlspecialchars($label) . ':</label>';
$formHtml .= '<input type="text" id="' . htmlspecialchars($field) . '" class="form-control" name="' . htmlspecialchars($field) . '" placeholder="' . htmlspecialchars($label) . '"><br><br>';
}
}
return $formHtml;
}
?>
<?php if ($accessCat): ?>
<?php
// Split the selected category into category and subcategory
list($category, $subcategory) = explode('/', $accessCat);
// Check if the selected category and subcategory exist
if (isset($categories[$category][$subcategory])) {
$fields = $categories[$category][$subcategory];
?>
<h2><?= htmlspecialchars($subcategory) ?></h2>
<div method="post" class="_carContainer image-preview">
<?= generateFormFields($fields) ?>
<!-- input type="submit" value="إرسال" -->
</div>
<?php
} else {
echo '<p class="error-message">الفئة أو التصنيف المحدد غير موجود.</p>';
}
?>
<?php endif; ?>
<div class="form-group">
<label for="berid">Berid:</label>
<input type="text" id="berid" name="berid" class="form-control" required>
</div>
<div class="form-group">
<label for="hetef">Hetef:</label>
<input type="text" id="hetef" name="hetef" class="form-control" required>
</div>
<div class="form-group">
<label for="country">Country:</label>
<input type="text" id="country" name="country" class="form-control" required>
</div>
<div class="form-group">
<label for="location_city">City:</label>
<input type="text" id="location_city" name="location_city" class="form-control" required>
</div>
<div class="form-group">
<label for="price">Price:</label>
<input type="text" id="price" name="price" class="form-control" required>
</div>
<div class="form-group">
<label for="el3omla">Currency:</label>
<input type="text" id="el3omla" name="el3omla" class="form-control" required>
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea id="description" name="description" class="form-control" rows="4" required></textarea>
</div>
<div class="form-group">
<label for="quantity">Quantity:</label>
<input type="text" id="quantity" name="quantity" class="form-control" required>
</div>
<div class="form-group">
<label for="yearModel">Year:</label>
<input type="text" id="yearModel" name="yearModel" class="form-control" required>
</div>
<!-- div class="form-group">
<label for="views">Views:</label>
<input type="text" id="views" name="views" class="form-control" required>
</div -->
<!-- div class="form-group">
<label for="attributes">Attributes (JSON):</label>
<textarea id="attributes" name="attributes" class="form-control" rows="4" required></textarea>
</div -->
<div class="form-group form-check">
<input type="checkbox" id="delivery_available" name="delivery_available" class="form-check-input" value="1">
<label for="delivery_available" class="form-check-label"><?php echo $_SESSION['property19']; ?>Delivery Available</label>
</div>
<div class="form-group form-check">
<input type="checkbox" id="negotiable_price" name="negotiable_price" class="form-check-input" value="1">
<label for="negotiable_price" class="form-check-label"><?php echo $_SESSION['property16']; ?>Negotiable Price</label>
</div>
<div class="form-group">
<label for="status">Status:</label>
<input type="text" id="status" name="status" class="form-control" required>
</div>
<div class="form-group">
<label for="collector">Collector:</label>
<input type="text" id="collector" name="collector" class="form-control" required>
</div>
<input type="hidden" name="form_html" value="<?php echo htmlspecialchars($formHtml); ?>">
<button type="submit" class="btn btn-primary"><?php echo $_SESSION['goNUploadNsell']; ?></button>
</form>
<h2>Existing Records</h2>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Images</th>
<th>Category</th>
<th>Attributes / Delivery Available / Negotiable Price</th>
<th>Status</th>
<th>Collector</th>
</tr>
</thead>
<tbody>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo htmlspecialchars($row['idBathae3i']); ?></td>
<td style="max-width:300px;">
<?php
$images = explode(',', $row['images']);
foreach ($images as $image): ?>
<img src="<?php echo htmlspecialchars($image); ?>" alt="Image" style="max-width: 100px; margin-right: 5px;">
<?php endforeach; ?>
</td>
<td><?php echo htmlspecialchars($row['category']); ?></td>
<td><?php /*echo htmlspecialchars($row['attributes']);*/ ?>
<?php
// Start session if not already started
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
// Decode the JSON-encoded attributes field
$attributes = json_decode($row['attributes'], true);
?>
<div>
<?php
$formHtml = $attributes['form_html'];
$formData = $attributes['data'];
?>
<div class="details-container">
<div class="data-display details-list">
<?php foreach ($formData as $key => $value): ?>
<?php
// Find the translation for the current key
$translation = '';
//foreach ($_SESSION['translations']['category']['vehicles']['cars'] as $category) {
foreach ($_SESSION['translations'] as $category) {
if (isset($category[$key])) {
$translation = $category[$key];
break;
}else if (isset($category['vehicles'][$key])) {
$translation = $category[$key];
break;
}
}
?>
<li><strong><font color=brown class=_vkey><?php echo htmlspecialchars($translation ?: $key, ENT_QUOTES, 'UTF-8'); ?>:</font></strong> <?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); ?></li>
<?php endforeach; ?>
</div>
</div>
</div>
<br /><?php echo $_SESSION['property19']; ?>: <?php echo $row['delivery_available'] ? $_SESSION['yes'] : $_SESSION['no'] ; ?><br /><?php echo $_SESSION['property16']; ?>: <?php echo $row['negotiable_price'] ? $_SESSION['yes'] : $_SESSION['no']; ?></td>
<td><?php echo htmlspecialchars($row['status']); ?></td>
<td><?php echo htmlspecialchars($row['collector']); ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<script>
document.querySelector('#images').addEventListener('change', function() {
const preview = document.querySelector('#image-preview');
preview.innerHTML = '';
for (const file of this.files) {
const reader = new FileReader();
reader.onload = function(e) {
const img = document.createElement('img');
img.src = e.target.result;
img.alt = 'Image Preview';
preview.appendChild(img);
};
reader.readAsDataURL(file);
}
});
</script>
</body>
</html>
Form_html:
Data:
{"title":"moto sands for me","year":"2025","mileage":"10","condition":"new","engine_capacity":"950","transmission":"automatic","color":"red","service_history":"2024","country":"om","location_city":"nzwa","price":"1450","el3omla":"omr","description":"<?php\r\ninclude_once "settings.php"; // Ensure this file sets up $connessione (database connection)\r\n//include 'ar.php';\r\nif(isset($_GET["accessCat"])) $_SESSION["ad"]=$_GET["accessCat"]; //for the cntrol to dsply ads && (HIDE) not to display the cars brands logos\r\n$bId = htmlspecialchars($_GET['bId'] ?? $_GET['bId']);\r\n\r\n\r\n// Check if the 'accessCat' GET parameter is set\r\n$accessCat = isset($_GET['accessCat']) ? $_GET['accessCat'] : '';\r\n\r\n// Define available categories and their fields\r\n$categories = $_SESSION['translations']['category'];\r\n\r\n\r\n// Process form submission\r\nif ($_SERVER['REQUEST_METHOD'] === 'POST') {\r\n $category = $connessione->real_escape_string($_POST['accessCat'] ?? $_GET['accessCat']);\r\n $title = $connessione->real_escape_string($_POST['title'] ?? '');\r\n $berid = $connessione->real_escape_string($_POST['berid'] ?? '');\r\n $hetef = $connessione->real_escape_string($_POST['hetef'] ?? '');\r\n $country = $connessione->real_escape_string($_POST['country'] ?? '');\r\n $location_city = $connessione->real_escape_string($_POST['location_city'] ?? '');\r\n $price = $connessione->real_escape_string($_POST['price'] ?? '');\r\n $el3omla = $connessione->real_escape_string($_POST['el3omla'] ?? '');\r\n $description = $connessione->real_escape_string($_POST['description'] ?? '');\r\n $quantity = $connessione->real_escape_string($_POST['quantity'] ?? '');\r\n $yearModel = $connessione->real_escape_string($_POST['yearModel'] ?? $_GET['year']);\r\n $views = intval($_POST['views'] ?? 0);\r\n \r\n //$attributes = $connessione->real_escape_string($_POST['attributes'] ?? '');\r\n // Collect prod attributes data with default values\r\n $attributes__ = [\r\n 'brand' => $_GET['brand'] ?? '',\r\n 'year' => $yearModel ?? '',\r\n 'regional_specifications' => $_POST['property3'] ?? '',\r\n 'odometer' => $_POST['property4'] ?? '',\r\n 'cylinders' => $_POST['property5'] ?? '',\r\n 'transmission' => $_POST['property6'] ?? '',\r\n 'keys' => $_POST['property7'] ?? '',\r\n 'full_options' => $_POST['property8'] ?? '',\r\n 'fuel' => $_POST['property9'] ?? '',\r\n 'wheel_drive' => $_POST['property10'] ?? '',\r\n 'exterior_color' => $_POST['property11'] ?? '',\r\n 'interior_color' => $_POST['property12'] ?? '',\r\n 'maintenance_report' => $_POST['property13'] ?? '',\r\n 'car_status' => $_POST['property17'] ?? ''\r\n ];\r\n // Initialize an array to hold form data\r\n $formData = [];\r\n $formHtml = isset($_POST['form_html']) ? $_POST['form_html'] : '';\r\n // Check if 'form_html' is set and is an array\r\nif (isset($_POST['form_html']) && is_array($_POST['form_html'])) {\r\n foreach ($_POST['form_html'] as $key => $value) {\r\n // Sanitize each value\r\n $formData[$key] = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');\r\n }\r\n} else {\r\n echo 'Error: form_html is not set or not an array.';\r\n}\r\n\r\n// Output the sanitized form data\r\nforeach ($formData as $key => $value) {\r\n echo htmlspecialchars($key) . ': ' . htmlspecialchars($value) . '<br>';\r\n}\r\n \r\n // Build the JSON object for the attributes field\r\n $attributes = [\r\n 'form_html' => $formHtml,\r\n 'data' => $formData\r\n ];\r\n \r\n // Convert the attributes array to a JSON string\r\n $attributesJson = json_encode($attributes);\r\n \r\n // Sanitize the JSON string for safe insertion\r\n $attributes = $connessione->real_escape_string($attributesJson);\r\n\r\n //$attributes = $connessione->real_escape_string(json_encode($attributes));\r\n\r\n \r\n $delivery_available = isset($_POST['delivery_available']) ? 1 : 0;\r\n $negotiable_price = isset($_POST['negotiable_price']) ? 1 : 0;\r\n $status = $connessione->real_escape_string($_POST['status'] ?? '');\r\n $collector = $connessione->real_escape_string($_POST['collector'] ?? '');\r\n\r\n // Handle file uploads\r\n $images = [];\r\n if (isset($_FILES['images']) && !empty($_FILES['images']['name'][0])) {\r\n $uploadDir = 'uploads/';\r\n if (!is_dir($uploadDir)) {\r\n mkdir($uploadDir, 0755, true);\r\n }\r\n\r\n foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {\r\n $fileName = basename($_FILES['images']['name'][$key]);\r\n $uploadFile = $uploadDir . $fileName;\r\n if (move_uploaded_file($tmp_name, $uploadFile)) {\r\n $images[] = $uploadFile;\r\n }\r\n }\r\n }\r\n $imagesList = implode(',', $images);\r\n\r\n try {\r\n $sql = mysqli_query($connessione, "INSERT INTO `bathae3i` (\r\n `idBathae3i`, \r\n `images`, \r\n `category`, \r\n `title`, \r\n `berid`, \r\n `hetef`, \r\n `country`, \r\n `location_city`, \r\n `price`, \r\n `el3omla`, \r\n `description`, \r\n `quantity`, \r\n `chronoBathae3`, \r\n `views`, \r\n `attributes`, \r\n `delivery_available`, \r\n `negotiable_price`, \r\n `status`, \r\n `collector`\r\n ) VALUES (\r\n NULL, '$imagesList', '$category', '$title', '$berid', '$hetef', '$country', \r\n '$location_city', '$price', '$el3omla', '$description', '$quantity', \r\n '".time()."', $views, '$attributes', $delivery_available, $negotiable_price, \r\n '$status', '$collector'\r\n )");\r\n \r\n if (!$sql) {\r\n die('Error: ' . htmlspecialchars($connessione->error));\r\n }\r\n } catch(Exception $e) {\r\n echo "Exception: " . $e->getMessage();\r\n }\r\n}\r\n\r\n// Retrieve records from the database\r\n$sql = "SELECT * FROM `bathae3i` WHERE idBathae3i = '" . $bId . "'";\r\n$result = $connessione->query($sql);\r\n?>\r\n\r\n<!DOCTYPE html>\r\n<html <?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"lang=ar dir=rtl"; else echo"lang=en dir=ltr"; ?>>\r\n<head>\r\n <meta charset="UTF-8">\r\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\r\n <title>Bathae3i Management</title>\r\n <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css__">\r\n <style>\r\n body {\r\n <?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"lang=ar dir=rtl"; else echo"lang=en dir=ltr"; ?>\r\n background-color: #f8f9fa;\r\n font-family: Arial, sans-serif;\r\n }\r\n .container {\r\n max-width: 1200px;\r\n margin: 20px auto;\r\n padding: 20px;\r\n background-color: #ffffff;\r\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);\r\n border-radius: 8px;\r\n }\r\n .form-control {\r\n display: block;\r\n width: 100%;\r\n height: calc(1.5em + .75rem + 2px);\r\n padding: .375rem .75rem;\r\n margin-top: 3px;\r\n font-size: 1rem;\r\n font-weight: 400;\r\n line-height: 1.5;\r\n color: #495057;\r\n background-color: #fff;\r\n background-clip: padding-box;\r\n border: 1px solid #ced4da;\r\n border-radius: .25rem;\r\n transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;\r\n}\r\n.btn {\r\n display: inline-block;\r\n font-weight: 400;\r\n color: #212529;\r\n text-align: center;\r\n vertical-align: middle;\r\n -webkit-user-select: none;\r\n -moz-user-select: none;\r\n -ms-user-select: none;\r\n user-select: none;\r\n background-color: transparent;\r\n border: 1px solid transparent;\r\n padding: .375rem .75rem;\r\n font-size: 1rem;\r\n line-height: 1.5;\r\n border-radius: .25rem;\r\n transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;\r\n}\r\n.btn-primary {\r\n color: #fff;\r\n background-color: #007bff;\r\n border-color: #007bff;\r\n}\r\n h1 {\r\n margin-bottom: 20px;\r\n }\r\n form {\r\n margin-bottom: 30px;\r\n }\r\n .form-group {\r\n margin-bottom: 15px;\r\n }\r\n .form-control, .form-check-input {\r\n border-radius: 4px;\r\n }\r\n .custom-file-input {\r\n display: none;\r\n }\r\n \r\n \r\n .custom-file-upload {\r\n border: 2px solid #007bff;\r\n border-radius: 8px;\r\n display: inline-block;\r\n padding: 12px 24px;\r\n cursor: pointer;\r\n background: linear-gradient(135deg, #007bff 0%, #00d2ff 100%);\r\n color: #ffffff;\r\n text-align: center;\r\n font-weight: bold;\r\n font-size: 16px;\r\n transition: all 0.3s ease;\r\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\r\n position: relative;\r\n }\r\n \r\n .custom-file-upload:hover {\r\n background: linear-gradient(135deg, #00d2ff 0%, #007bff 100%);\r\n color: #f0f0f0;\r\n transform: scale(1.05);\r\n }\r\n \r\n .custom-file-upload:before {\r\n content: '📁 ';\r\n position: absolute;\r\n <?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"right: 0px;"; else echo"left: 0px;"; ?>\r\n top: 40%;\r\n transform: translateY(-50%);\r\n font-size: 18px;\r\n }\r\n \r\n .custom-file-input {\r\n display: none;\r\n }\r\n \r\n .image-preview {\r\n display: flex;\r\n flex-wrap: wrap;\r\n margin-top: 10px;\r\n }\r\n \r\n .image-preview img {\r\n max-width: 100px;\r\n margin-right: 5px;\r\n border-radius: 8px;\r\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\r\n }\r\n \r\n \r\n .image-preview {\r\n display: flex;\r\n flex-wrap: wrap;\r\n margin-top: 10px;\r\n border: 2px dashed #007bff;\r\n border-radius: 8px;\r\n padding: 10px;\r\n background-color: #f8f9fa;\r\n min-height: 120px;\r\n position: relative;\r\n overflow: auto;\r\n }\r\n \r\n .image-preview .placeholder {\r\n position: absolute;\r\n top: 50%;\r\n left: 50%;\r\n transform: translate(-50%, -50%);\r\n color: #007bff;\r\n font-size: 18px;\r\n font-weight: bold;\r\n text-align: center;\r\n pointer-events: none;\r\n }\r\n \r\n .image-preview img {\r\n max-width: 100px;\r\n margin: 5px;\r\n border-radius: 8px;\r\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);\r\n }\r\n\r\n\r\n table {\r\n width: 100%;\r\n border-collapse: collapse;\r\n }\r\n table th, table td {\r\n border: 1px solid #dee2e6;\r\n padding: 12px;\r\n text-align: left;\r\n }\r\n table th {\r\n background-color: #007bff;\r\n color: #ffffff;\r\n }\r\n table td {\r\n background-color: #ffffff;\r\n }\r\n .attributes-list {\r\n white-space: pre-wrap; /* Preserve whitespace for line breaks */\r\n }\r\n \r\n \r\n .details-list {\r\n list-style-type: none;\r\n padding: 0;\r\n margin: 0;\r\n }\r\n .details-list li:nth-child(even) {\r\n background-color: #f9f9f9;\r\n }\r\n .details-list li {\r\n padding: 10px;\r\n border-bottom: 1px solid #eee;\r\n }\r\n .details-container {\r\n background-color: #fff;\r\n border: 1px solid #ddd;\r\n padding: 20px;\r\n margin-bottom: 20px;\r\n font-family: Arial, sans-serif;\r\n width: 100%;\r\n margin: 0 auto;\r\n box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);\r\n }\r\n ._vkey{\r\n <?php if(!isset($_SESSION['lang']) || $_SESSION['lang']=="ar") echo"margin-left: 40px;"; else echo"margin-right: 40px;"; ?>\r\n }\r\n </style>\r\n</head>\r\n<body>\r\n\r\n<div class="container">\r\n <h1>Insert New Record</h1>\r\n\r\n <form method="post" action="?accessCat=<?php echo $_GET['accessCat']; ?>&brand=<?php echo $_GET['brand']; ?>&year=<?php echo $_GET['year']; ?>" enctype="multipart/form-data">\r\n <!--div class="form-group">\r\n <label for="category">Category:</label>\r\n <input type="text" id="category" name="accessCat" class="form-control" required>\r\n </div -->\r\n\r\n <div class="form-group">\r\n <label for="images" class="custom-file-upload">\r\n <span><?php echo $_SESSION["imageUpload"]; ?></span>\r\n </label>\r\n <input type="file" id="images" name="images[]" class="custom-file-input" accept="image/*" multiple>\r\n <div class="image-preview" id="image-preview">\r\n <div class="placeholder"><?php echo $_SESSION["imagesselected"]; ?></div>\r\n </div>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="title">Title:</label>\r\n <input type="text" id="title" name="title" class="form-control" required>\r\n </div>\r\n \r\n <?php if($_GET["accessCat"]=="cars")include_once"_carsSpecificities.php"; ?>\r\n <?php //include_once"_vpcategoriesForms.php"; \r\n \r\n \r\n // Function to generate form fields\r\n function generateFormFields($fields) {\r\n $formHtml = '';\r\n foreach ($fields as $field => $label) {\r\n if (is_array($label)) { // Check if the field has subvalues\r\n $formHtml .= '<label for="' . htmlspecialchars($field) . '">' . htmlspecialchars($label['type']) . ':</label>';\r\n $formHtml .= '<select id="' . htmlspecialchars($field) . '" name="' . htmlspecialchars($field) . '" class="form-control">';\r\n foreach ($label as $subValue => $subLabel) {\r\n if ($subValue !== 'type') { // Skip the 'type' key\r\n $formHtml .= '<option value="' . htmlspecialchars($subValue) . '">' . htmlspecialchars($subLabel) . '</option>';\r\n }\r\n }\r\n $formHtml .= '</select><br><br>';\r\n } else {\r\n $formHtml .= '<label for="' . htmlspecialchars($field) . '">' . htmlspecialchars($label) . ':</label>';\r\n $formHtml .= '<input type="text" id="' . htmlspecialchars($field) . '" class="form-control" name="' . htmlspecialchars($field) . '" placeholder="' . htmlspecialchars($label) . '"><br><br>';\r\n }\r\n }\r\n return $formHtml;\r\n }\r\n ?>\r\n \r\n <?php if ($accessCat): ?>\r\n <?php\r\n // Split the selected category into category and subcategory\r\n list($category, $subcategory) = explode('/', $accessCat);\r\n \r\n // Check if the selected category and subcategory exist\r\n if (isset($categories[$category][$subcategory])) {\r\n $fields = $categories[$category][$subcategory];\r\n ?>\r\n <h2><?= htmlspecialchars($subcategory) ?></h2>\r\n <div method="post" class="_carContainer image-preview">\r\n <?= generateFormFields($fields) ?>\r\n <!-- input type="submit" value="إرسال" -->\r\n </div>\r\n <?php\r\n } else {\r\n echo '<p class="error-message">الفئة أو التصنيف المحدد غير موجود.</p>';\r\n }\r\n ?>\r\n <?php endif; ?>\r\n\r\n\r\n <div class="form-group">\r\n <label for="berid">Berid:</label>\r\n <input type="text" id="berid" name="berid" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="hetef">Hetef:</label>\r\n <input type="text" id="hetef" name="hetef" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="country">Country:</label>\r\n <input type="text" id="country" name="country" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="location_city">City:</label>\r\n <input type="text" id="location_city" name="location_city" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="price">Price:</label>\r\n <input type="text" id="price" name="price" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="el3omla">Currency:</label>\r\n <input type="text" id="el3omla" name="el3omla" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="description">Description:</label>\r\n <textarea id="description" name="description" class="form-control" rows="4" required></textarea>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="quantity">Quantity:</label>\r\n <input type="text" id="quantity" name="quantity" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="yearModel">Year:</label>\r\n <input type="text" id="yearModel" name="yearModel" class="form-control" required>\r\n </div>\r\n\r\n <!-- div class="form-group">\r\n <label for="views">Views:</label>\r\n <input type="text" id="views" name="views" class="form-control" required>\r\n </div -->\r\n\r\n <!-- div class="form-group">\r\n <label for="attributes">Attributes (JSON):</label>\r\n <textarea id="attributes" name="attributes" class="form-control" rows="4" required></textarea>\r\n </div -->\r\n\r\n <div class="form-group form-check">\r\n <input type="checkbox" id="delivery_available" name="delivery_available" class="form-check-input" value="1">\r\n <label for="delivery_available" class="form-check-label"><?php echo $_SESSION['property19']; ?>Delivery Available</label>\r\n </div>\r\n\r\n <div class="form-group form-check">\r\n <input type="checkbox" id="negotiable_price" name="negotiable_price" class="form-check-input" value="1">\r\n <label for="negotiable_price" class="form-check-label"><?php echo $_SESSION['property16']; ?>Negotiable Price</label>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="status">Status:</label>\r\n <input type="text" id="status" name="status" class="form-control" required>\r\n </div>\r\n\r\n <div class="form-group">\r\n <label for="collector">Collector:</label>\r\n <input type="text" id="collector" name="collector" class="form-control" required>\r\n </div>\r\n\r\n \r\n <input type="hidden" name="form_html" value="<?php echo htmlspecialchars($formHtml); ?>">\r\n <button type="submit" class="btn btn-primary"><?php echo $_SESSION['goNUploadNsell']; ?></button>\r\n </form>\r\n\r\n <h2>Existing Records</h2>\r\n <table class="table">\r\n <thead>\r\n <tr>\r\n <th>ID</th>\r\n <th>Images</th>\r\n <th>Category</th>\r\n <th>Attributes / Delivery Available / Negotiable Price</th>\r\n <th>Status</th>\r\n <th>Collector</th>\r\n </tr>\r\n </thead>\r\n <tbody>\r\n <?php while ($row = $result->fetch_assoc()): ?>\r\n <tr>\r\n <td><?php echo htmlspecialchars($row['idBathae3i']); ?></td>\r\n <td style="max-width:300px;">\r\n <?php \r\n $images = explode(',', $row['images']);\r\n foreach ($images as $image): ?>\r\n <img src="<?php echo htmlspecialchars($image); ?>" alt="Image" style="max-width: 100px; margin-right: 5px;">\r\n <?php endforeach; ?>\r\n </td>\r\n <td><?php echo htmlspecialchars($row['category']); ?></td>\r\n <td><?php /*echo htmlspecialchars($row['attributes']);*/ ?>\r\n \r\n <?php\r\n // Start session if not already started\r\n if (session_status() === PHP_SESSION_NONE) {\r\n session_start();\r\n }\r\n \r\n // Decode the JSON-encoded attributes field\r\n $attributes = json_decode($row['attributes'], true);\r\n ?>\r\n <div>\r\n <?php\r\n $formHtml = $attributes['form_html'];\r\n $formData = $attributes['data'];\r\n ?>\r\n <div class="details-container">\r\n <div class="data-display details-list"> \r\n <?php foreach ($formData as $key => $value): ?>\r\n <?php\r\n // Find the translation for the current key\r\n $translation = '';\r\n //foreach ($_SESSION['translations']['category']['vehicles']['cars'] as $category) {\r\n foreach ($_SESSION['translations'] as $category) {\r\n if (isset($category[$key])) {\r\n $translation = $category[$key];\r\n break;\r\n }else if (isset($category['vehicles'][$key])) {\r\n $translation = $category[$key];\r\n break;\r\n }\r\n }\r\n ?>\r\n <li><strong><font color=brown class=_vkey><?php echo htmlspecialchars($translation ?: $key, ENT_QUOTES, 'UTF-8'); ?>:</font></strong> <?php echo htmlspecialchars($value, ENT_QUOTES, 'UTF-8'); ?></li>\r\n <?php endforeach; ?>\r\n </div>\r\n </div>\r\n </div>\r\n\r\n\r\n \r\n \r\n <br /><?php echo $_SESSION['property19']; ?>: <?php echo $row['delivery_available'] ? $_SESSION['yes'] : $_SESSION['no'] ; ?><br /><?php echo $_SESSION['property16']; ?>: <?php echo $row['negotiable_price'] ? $_SESSION['yes'] : $_SESSION['no']; ?></td>\r\n <td><?php echo htmlspecialchars($row['status']); ?></td>\r\n <td><?php echo htmlspecialchars($row['collector']); ?></td>\r\n </tr>\r\n <?php endwhile; ?>\r\n </tbody>\r\n </table>\r\n</div>\r\n\r\n<script>\r\ndocument.querySelector('#images').addEventListener('change', function() {\r\n const preview = document.querySelector('#image-preview');\r\n preview.innerHTML = '';\r\n for (const file of this.files) {\r\n const reader = new FileReader();\r\n reader.onload = function(e) {\r\n const img = document.createElement('img');\r\n img.src = e.target.result;\r\n img.alt = 'Image Preview';\r\n preview.appendChild(img);\r\n };\r\n reader.readAsDataURL(file);\r\n }\r\n});\r\n</script>\r\n\r\n</body>\r\n</html>\r\n","quantity":"1","yearModel":"2025","negotiable_price":"1","status":"new","collector":"no"}