function remove_section_images($connection, $id)
{
    $images = get_section_images($connection, $id);
    foreach ($images as $image) {
        remove_image_file($image['filePath']);
    }
    $delete_images_by_section_id_stmt = delete_images_by_section_id_stmt($connection);
    $delete_images_by_section_id_stmt->bind_param("i", $id);
    catch_execution_error($delete_images_by_section_id_stmt->execute(), $connection);
}
function get_sections($connection)
{
    $connection->begin_transaction();
    $get_section_query = <<<SQL
select s.id, s.type, s.title
from section s
order by s.order asc;
SQL;
    if ($results = $connection->query($get_section_query)) {
        $result_array = [];
        while ($row = $results->fetch_assoc()) {
            $id = $row['id'];
            $type = $row['type'];
            $array_builder = array("id" => $id, "title" => $row['title'], "type" => $type, "text" => "", "buttonText" => "", "images" => [], "youtubes" => []);
            if ($type == "TEXT" || $type == "INTRO" || $type == "JOIN" || $type == "MODS") {
                $array_builder["text"] = get_section_text($connection, $id);
                if ($type == "JOIN" || $type == "MODS") {
                    $array_builder["buttonText"] = get_section_button_text($connection, $id);
                }
            } else {
                if ($type == "MEDIA") {
                    $array_builder["images"] = get_section_images($connection, $id);
                    $array_builder["youtubes"] = get_section_youtubes($connection, $id);
                }
            }
            $result_array[] = $array_builder;
        }
        print "[[\"SUCCESS\"],";
        print json_encode($result_array);
        print "]";
        $results->close();
    } else {
        $error = $connection->error;
        print "[[\"ERROR\"],[\"{$error}\"]]";
        exit;
    }
    $connection->commit();
}