<?php
include '../config.php';
function toFiveDigit($number) {
    return str_pad($number, 5, "0", STR_PAD_LEFT);
}

if (isset($_POST['teams'])) {
    $teams = $_POST['teams'];

    foreach ($teams as $position => $team) {
        $id = intval($team['id']);
        $name = $team['name'];
        $status = ($team['status'] === 'Show') ? 'Show' : 'Hide';

        $post_form_data = array(
            "Position" => toFiveDigit($position),
            "TeamName" => $name,
            "Status"   => $status
        );

        // Update database
        $insert_now = UpdateData('mahamudfutureit_team', 'ID', $id, $post_form_data);
    }

    echo "success";
}
