query($query)) {
while ($c_type = $result->fetch_assoc()) {
$return_array[] = [
"type_name" => $c_type['type_name'],
"currency" => $c_type['currency']
];
}
}
echo json_encode(array(
'data' => $return_array,
'result' => 'ok'
));
} else if (htmlspecialchars($_POST["func"]) == "CreateCustomerType") {
$type_name = ucfirst(trim(htmlspecialchars($_POST["type_name"])));
$currency = strtoupper(trim(htmlspecialchars($_POST["currency"])));
if (empty($type_name) || empty($currency)) {
echo json_encode(array(
'result' => 'Üres paraméterekkel nem hozhat létre vevőtípust'
));
} else {
$sql = mysqli_query($conn,"SELECT ct_id FROM customer_types WHERE is_active = 0 LIMIT 1");
$data = mysqli_fetch_array($sql);
if ($data != null) {
$ct_id = $data["ct_id"];
$sql = mysqli_query($conn,"UPDATE customer_types SET type_name='$type_name',currency='$currency',category_name='Alapértelmezett',price=0,is_active=1 WHERE ct_id = '$ct_id'");
} else {
$sql = mysqli_query($conn,"INSERT INTO customer_types(type_name, currency, category_name, price, is_active) VALUES ('$type_name','$currency','Alapértelmezett',0,1)");
}
echo json_encode(array( 'result' => 'ok' ));
}
} else if (htmlspecialchars($_POST["func"]) == "OpenCustomerType") {
$type_name = htmlspecialchars($_POST["type_name"]);
$return_array = [];
$query = "SELECT * FROM customer_types WHERE type_name = '$type_name' and is_active = 1 ORDER BY category_name ASC";
if ($result = $conn->query($query)) {
while ($c_type = $result->fetch_assoc()) {
$return_array[] = [
"ct_id" => $c_type['ct_id'],
"currency" => $c_type['currency'],
"category_name" => $c_type['category_name'],
"price" => $c_type['price'],
"is_active" => $c_type['is_active']
];
}
}
echo json_encode(array(
'data' => $return_array,
'result' => 'ok'
));
} else if (htmlspecialchars($_POST["func"]) == "EditCategoryName") {
$type_name = htmlspecialchars($_POST["type_name"]);
$category_name = ucfirst(trim(htmlspecialchars($_POST["category_name"])));
$price = floatval($_POST["price"] ?? 0);
if (empty($type_name) || empty($category_name)) {
echo json_encode(array( 'result' => 'Üres paraméterekkel nem hozhat létre árkategóriát' ));
} else {
$sql = mysqli_query($conn,"SELECT currency FROM customer_types WHERE type_name = '$type_name' LIMIT 1");
$data = mysqli_fetch_array($sql);
if ($data == null) {
echo json_encode(array( 'result' => 'Nem létező vevőtípus lett megadva' ));
} else {
$currency = $data['currency'];
$sql = mysqli_query($conn,"SELECT ct_id FROM customer_types WHERE type_name = '$type_name' and category_name='$category_name'");
$data = mysqli_fetch_array($sql);
if ($data != null) {
$ct_id = $data["ct_id"];
$sql = mysqli_query($conn,"UPDATE customer_types SET type_name='$type_name',currency='$currency',category_name='$category_name',price=$price,is_active=1 WHERE ct_id = '$ct_id'");
} else {
$sql = mysqli_query($conn,"SELECT ct_id FROM customer_types WHERE is_active = 0 LIMIT 1");
$data = mysqli_fetch_array($sql);
if ($data != null) {
$ct_id = $data["ct_id"];
$sql = mysqli_query($conn,"UPDATE customer_types SET type_name='$type_name',currency='$currency',category_name='$category_name',price=$price,is_active=1 WHERE ct_id = '$ct_id'");
} else {
$sql = mysqli_query($conn,"INSERT INTO customer_types(type_name, currency, category_name, price, is_active) VALUES ('$type_name','$currency','$category_name',$price,1)");
}
}
}
echo json_encode(array( 'result' => 'ok' ));
}
} else if (htmlspecialchars($_POST["func"]) == "DisableCategory") {
$ct_id = htmlspecialchars($_POST["ct_id"]);
$sql = mysqli_query($conn,"UPDATE customer_types SET is_active = 0 WHERE ct_id = '$ct_id'");
echo json_encode(array( 'result' => 'ok' ));
}
exit();
}
?>
Kezelőfelület