<?php
if ($first_column_selected_group) {
    echo '<div class="col-sm-12">';
    foreach ($first_column_selected_group as $group_value) {
        ?>
        <div class="col-sm-4">
            <div class="checkbox checkbox-success">
                <input type="checkbox"
                       onchange="checkGroupPersonID(this.value)"
                       id="group_id<?php echo $group_value->group_id; ?>" 
                       class="styled"
                       name="group_id[]"
                       value="<?php echo $group_value->group_id; ?>" checked >
                <label for="<?php echo $group_value->group_name; ?>" class="text-justify" ><?php echo $group_value->group_name; ?></label>
            </div>
            <div class="col-sm-12" style="color: red" id="group_checkbox_error<?php echo $group_value->group_id; ?>"></div>
        </div>
        <?php
    }
    echo ' </div>';
}

if ($second_column_selected_group) {
    echo '<div class="col-sm-12">';
    foreach ($second_column_selected_group as $group_value) {
        ?>
        <div class="col-sm-4">
            <div class="checkbox checkbox-success">
                <input type="checkbox"
                       onchange="checkGroupPersonID(this.value)"
                       id="group_id<?php echo $group_value->group_id; ?>" 
                       class="styled"
                       name="group_id[]"
                       value="<?php echo $group_value->group_id; ?>" checked>
                <label for="<?php echo $group_value->group_name; ?>" class="text-justify" ><?php echo $group_value->group_name; ?></label>
            </div>
            <div class="col-sm-12" style="color: red" id="group_checkbox_error<?php echo $group_value->group_id; ?>"></div>
        </div>
        <?php
    }
    echo ' </div>';
}

if ($all_group) {
    if ($first_column_group) {
        echo '<div class="col-sm-12">';
        foreach ($first_column_group as $group_value) {
            ?>
            <div class="col-sm-4">
                <div class="checkbox checkbox-success">
                    <input type="checkbox"
                           onchange="checkGroupPersonID(this.value)"
                           id="group_id<?php echo $group_value->group_id; ?>" 
                           class="styled"
                           name="group_id[]"
                           value="<?php echo $group_value->group_id; ?>" >
                    <label for="<?php echo $group_value->group_name; ?>" class="text-justify" ><?php echo $group_value->group_name; ?></label>
                </div>
                <div class="col-sm-12" style="color: red" id="group_checkbox_error<?php echo $group_value->group_id; ?>"></div>
            </div>
            <?php
        }
        echo ' </div>';
    }

    if ($second_column_group) {
        echo '<div class="col-sm-12">';
        foreach ($second_column_group as $group_value) {
            ?>
            <div class="col-sm-4">
                <div class="checkbox checkbox-success">
                    <input type="checkbox"
                           onchange="checkGroupPersonID(this.value)"
                           id="group_id<?php echo $group_value->group_id; ?>" 
                           class="styled"
                           name="group_id[]"
                           value="<?php echo $group_value->group_id; ?>" >
                    <label for="<?php echo $group_value->group_name; ?>" class="text-justify" ><?php echo $group_value->group_name; ?></label>
                </div>
                <div class="col-sm-12" style="color: red" id="group_checkbox_error<?php echo $group_value->group_id; ?>"></div>
            </div>
            <?php
        }
        echo ' </div>';
    }

    if ($third_column_group) {
        echo '<div class="col-sm-12">';
        foreach ($third_column_group as $group_value) {
            ?>
            <div class="col-sm-4">
                <div class="checkbox checkbox-success">
                    <input type="checkbox"
                           onchange="checkGroupPersonID(this.value)"
                           id="group_id<?php echo $group_value->group_id; ?>" 
                           class="styled"
                           name="group_id[]"
                           value="<?php echo $group_value->group_id; ?>" >
                    <label for="<?php echo $group_value->group_name; ?>" class="text-justify" ><?php echo $group_value->group_name; ?></label>
                </div>
                <div class="col-sm-12" style="color: red" id="group_checkbox_error<?php echo $group_value->group_id; ?>"></div>
            </div>
            <?php
        }
        echo ' </div>';
    }
} else {
    echo $message;
}