function group_timeline_layout_pagesetup()
{
    $group = elgg_get_page_owner_entity();
    if (!empty($group) && elgg_instanceof($group, "group")) {
        if (group_timeline_layout_allow($group) && $group->canEdit()) {
            // add menu item for group admins to edit layout
            elgg_register_menu_item("page", array("name" => "group_layout", "text" => elgg_echo("group_timeline_layout:edit"), "href" => "group_timeline_layout/" . $group->getGUID(), "context" => "group_profile"));
        }
        if ($layout = group_timeline_layout_get_layout($group)) {
            elgg_register_css("timeline_group_layout", "group_timeline_layout/group_css/" . $layout->getGUID() . "/" . $layout->time_updated . ".css");
            elgg_load_css("timeline_group_layout");
        }
    }
}
<?php

$group_guid = (int) get_input("group_guid");
$dataroot = elgg_get_config("dataroot");
if (!empty($group_guid) && ($group = get_entity($group_guid))) {
    if (elgg_instanceof($group, "group") && $group->canEdit()) {
        $existing = false;
        if ($layout = group_timeline_layout_get_layout($group)) {
            $existing = true;
        } else {
            $layout = new ElggObject();
            $layout->subtype = GROUP_TIMELINE_LAYOUT_SUBTYPE;
            $layout->owner_guid = $group->getGUID();
            $layout->container_guid = $group->getGUID();
            $layout->access_id = ACCESS_PUBLIC;
            $layout->save();
        }
        $enable_background = get_input("enable_background", "no");
        $layout->enable_background = $enable_background;
        if ($enable_background == "yes") {
            if ($file_contents = get_uploaded_file("backgroundFile")) {
                $background = $_FILES["backgroundFile"];
                if (stristr($background["type"], "image")) {
                    if (!is_dir($dataroot . "group_timeline_layout/")) {
                        mkdir($dataroot . "group_timeline_layout/");
                    }
                    if (!is_dir($dataroot . "group_timeline_layout/backgrounds/")) {
                        mkdir($dataroot . "group_timeline_layout/backgrounds/");
                    }
                    if (file_put_contents($dataroot . "group_timeline_layout/backgrounds/" . $group->getGUID() . ".jpg", $file_contents)) {
                        system_message(elgg_echo("group_timeline_layout:action:save:success:background"));