?>
" size="120" /></td></tr>
<tr><td><label for="cdn">CDN</label></td><td> <input type="text" name="cdn" value="" size="120" /> (Optional)</td></tr>
<tr><td><label for="urlbase">Package URL base</label></td><td> <input type="text" name="urlbase" value="" size="120" /> (Optional)</td></tr>
<tr><td></td><td><input type="submit" value="Generate" /></td></tr>
</table>
</form>

<?php 
} else {
    $action = $_GET['action'];
    $timestamp = isset($_GET['t']) ? $_GET['t'] : '';
    // Redirect with a timestamp if we didn't get one.
    if ($timestamp == '') {
        $timestamp = time();
        $url = http_build_url(pugpig_self_link(), array("query" => "t={$timestamp}"), HTTP_URL_JOIN_QUERY);
        header("Location: " . $url);
        exit;
    }
    $tmp_root = $_GET['tf'];
    if ($action == 'generatepackagefiles') {
        $content_xml_url = $_GET['c'];
        $final_package_url = $_GET['p'];
        $concurrent_connections = $_GET['conc'];
        $relative_path = $_GET['pbp'];
        // We have to package from the root
        $edition_tag = '';
        $return_manifest_asset_urls = FALSE;
        $save_root = $_GET['pf'];
        $cdn = isset($_GET['cdn']) ? $_GET['cdn'] : '';
        $package_url_base = isset($_GET['urlbase']) ? $_GET['urlbase'] : '';
function pugpig_get_rss_root($edition_id)
{
    $edition = pugpig_get_edition($edition_id, false);
    $d = new DomDocument('1.0', 'UTF-8');
    $feed = $d->createElement('rss');
    $feed->setAttribute('version', '2.0');
    $channel = $d->createElement('channel');
    $feed->appendChild($channel);
    $channel->appendChild(newElement($d, 'title', $edition['title']));
    $channel->appendChild(newElement($d, 'link', pugpig_self_link()));
    $channel->appendChild(newElement($d, 'pubDate', pugpig_date_kindle(pugpig_get_edition_update_date($edition, true))));
    $item = null;
    foreach (pugpig_get_kindle_page_array($edition) as $page) {
        if ($page['level'] == 1) {
            $item = $d->createElement('item');
            $abs_path = pugpig_abs_link('editions/' . pugpig_get_atom_tag($edition['key']) . '/data/' . $page['id'] . '/kindle.rss');
            $item->appendChild(newElement($d, 'link', $abs_path));
            // $channel->appendChild($item);
        }
        // If we have a Level 1 node, attach it once we know we have a child
        // Having a section without any children breaks everything
        if ($page['level'] > 1 && $item != null) {
            // print_r($page['title']);
            $channel->appendChild($item);
            $item = null;
        }
    }
    $d->appendChild($feed);
    return $d;
}