function buildEnvelope()
{
    $envelope = new Envelope();
    if (isset($_POST["subject"])) {
        $envelope->Subject = $_POST["subject"];
    } else {
        $_SESSION["errorMessage"] = "You must have a subject";
        header("Location: error.php");
    }
    if ($_POST["emailBlurb"]) {
        $envelope->EmailBlurb = $_POST["emailBlurb"];
    } else {
        $_SESSION["errorMessage"] = "You must have an email blurb";
        header("Location: error.php");
    }
    $envelope->AccountId = $_SESSION["AccountID"];
    $envelope->Recipients = constructRecipients();
    $envelope->Tabs = addTabs(count($envelope->Recipients));
    $envelope = processOptions($envelope);
    $envelope->Documents = getDocuments();
    return $envelope;
}
) );

$script->startup();

$options = $script->getOptions(
    '[clusterIdentifier:][exclude:]',
    "",
    array(
        'clusterIdentifier' => 'Comma separated list of cluster identifiers (or value all if all of them)',
        'exclude' => 'Boolean flag deciding whether the script should be run for all clusters except given (default: false)'
    )
);
$script->initialize();

try {
    $options = processOptions($options);
    $clusters = $options['clusters'];
    foreach($clusters as $cluster)
    {
        $cli->output("Starting new season for cluster {$cluster}");
        QuizPlayerScoring::startNewSeason($cluster);
    }
} catch (Exception $e)
{
    $cli->error($e->getMessage());
    $script->shutdown(1);
}


$script->shutdown();
<?php

$configuration = parse_ini_file('config.cfg');
$options = processOptions(getopt("s:i:", array('set:', 'id:')));
$harvestableIds = readHarvestableIds('harvestable/' . $options['id'] . '.txt');
foreach ($harvestableIds as $id) {
    echo $id, "\n";
    $cmd = sprintf('php oai2json.php --id="%s" --set="%s"', $id, $options['set']);
    exec($cmd);
}
function processOptions($input)
{
    $options = array();
    processOption($options, $input, 'set', 's');
    processOption($options, $input, 'id', 'i');
    return $options;
}
function processOption(&$options, $input, $long, $short)
{
    if (isset($input[$long]) && !empty($input[$long])) {
        $options[$long] = urlencode($input[$long]);
    }
    if (!isset($options[$long]) && isset($input[$short]) && !empty($input[$short])) {
        $options[$long] = urlencode($input[$short]);
    }
}
function readHarvestableIds($file)
{
    $ids = array();
    $handle = fopen($file, "r");
    if ($handle) {
<?php

define('LN', "\n");
define('FILE_NAME_TEMPLATE', 'europeana-oai-pmh-import-%08d.json');
define('ID_PREFIX', 'http://data.europeana.eu/item/');
define('DAY', 60 * 60 * 24);
define('MONTH', 28 * DAY);
define('YEAR', 365 * DAY);
define('MAX_RETRY', 3);
require_once '../oai-pmh-lib/OAIHarvester.php';
// require_once('config.php');
$configuration = parse_ini_file('config.cfg');
$options = processOptions(getopt("s::i::f::", array('set::', 'id::', 'file::')));
$total = 0;
$times = array('t0' => microtime(TRUE), 't1' => microtime(TRUE));
$params = array('metadataPrefix' => 'edm');
if (isset($options['set'])) {
    $params['set'] = $options['set'];
    define('SET_BASED_FILE_NAME_TEMPLATE', $options['set'] . '/%08d.json');
    $dir = $configuration['OUTPUT_DIR'] . '/' . $options['set'];
    if (!file_exists($dir)) {
        if (!mkdir($dir)) {
            die('Failed to create directory: ' . $dir);
        }
    }
}
$verb = 'ListRecords';
if (isset($options['id'])) {
    $params['identifier'] = ID_PREFIX . $options['id'];
    unset($params['set']);
    define('ID_BASED_FILE_NAME_TEMPLATE', $options['set'] . '/individuals.json');