<?php
include 'db.php';

$id = $_POST['id'];
$phone = $_POST['branch_phone'];
$province = $_POST['province'];
$ntn = $_POST['ntn'];
$strn = $_POST['strn'];

$stmt = $conn->prepare("UPDATE branch_info SET branch_phone = ?, province = ?, ntn = ?, strn = ? WHERE id = ?");
$stmt->bind_param("ssssi", $phone, $province, $ntn, $strn, $id);
$stmt->execute();

// Handle logo upload
if (isset(
    $_FILES['branch_logo']) &&
    $_FILES['branch_logo']['error'] === UPLOAD_ERR_OK
) {
    $allowed_types = ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'];
    $file_type = mime_content_type($_FILES['branch_logo']['tmp_name']);
    if (in_array($file_type, $allowed_types)) {
        $target_path = 'assets/img/branch_logo.png';
        move_uploaded_file($_FILES['branch_logo']['tmp_name'], $target_path);
    }
}

header("Location: branch_list.php?success=1");
exit;
