#! /usr/local/bin/php -q
<?php
{
    Include_Once('../../../support/classes.php');
    Include_Once('../../../support/dbi.php3');
    $o_db = new acDB();
    $o_evt = $o_db->event(ACDB_CURRENT);
    /*
     * Only emit the header if necessary.
     */
    if (isset($REQUEST_METHOD)) {
        Header("Content-type: text/plain");
        $debug = false;
    }
    else {
        /*
         * Figure out if we have any special options..
         */
        if (isset($argv[1])) {
            $o_evt = $o_db->event($argv[1]);
        }
        $debug = isset($argv[2]);
    }

    /*
     * Mainline code.
     */
    $event = $o_evt->get('event');
?>
#! /bin/bash
export JAVA_HOME=/usr/lib/jvm/jre
export FOP='/usr/local/build/fop-0.20.5/fop.sh'

mkag() {
    echo -n "Generating agreement for UID $1:"
    php ./speaker-agreement.php "$1" <?= $event; ?> > sa-$2.fo 2> /dev/null
    $FOP -fo sa-$2.fo -pdf sa-$2.pdf >/dev/null
    echo " done."
}

if [ ! -z "$*" ] ; then
    for SPUID in $* ; do
        mkag $SPUID `php ./genid.php $SPUID` 2> /dev/null
    done
    exit
fi
<?php
    $person = array(); 
    /*
     * First, get the list of submitters (so we can discount them if
     * none of their submissions were accepted).
     */
    $sql = 'SELECT c.uid, c.cid, p.first_name, p.last_name, p.email '
        . 'FROM cfp AS c, person AS p '
        . "WHERE (event LIKE '" . $event . "') "
        . 'AND (p.uid = c.uid) ';
    $q = mysql_query($sql);
    while ($q && (list($uid, $cid, $f, $l, $e) = mysql_fetch_row($q))) {
        if (! isset($person[$uid])) {
            $person[$uid]['cfps'] = 0;
            $person[$uid]['fallback'] = 0;
            $person[$uid]['accepted'] = 0;
        }
        $person[$uid]['cfps']++;
        $person[$uid]['name'] = "$f $l <$e>";
    }
    /*
     * Now do the session speakers.  We need to do them separately
     * because they might not have been submitters.
     */
    $sql = 'SELECT ss.uid, ss.session_id, c.status, '
        . 'p.first_name, p.last_name, p.email '
        . 'FROM session_speaker AS ss, session AS s, cfp AS c, person AS p '
        . "WHERE (ss.event LIKE '" . $event . "') "
        . ' AND (s.id = ss.session_id) '
        . ' AND (c.event = ss.event) '
        . ' AND (c.cid = s.cid) '
        . ' AND FIND_IN_SET(c.status, "Accepted,Fallback") '
        . ' AND (p.uid = ss.uid) ';
    
    $q = mysql_query($sql);
    while ($q && ($row = mysql_fetch_row($q))) {
        list($uid, $id, $status, $f, $l, $e) = $row;
        if (! isset($person[$uid])) {
            $person[$uid]['cfps'] = 0;
            $person[$uid]['fallback'] = 0;
            $person[$uid]['accepted'] = 0;
        }
        $person[$uid][strtolower($status)]++;
        $person[$uid]['name'] = "$f $l <$e>";
    }
    foreach ($person as $uid => $rubbish) {
        $accepted = $person[$uid]['accepted'];
        $fallbacks = $person[$uid]['fallback'];
        $submitted = $person[$uid]['cfps'];
        if (($accepted + $fallbacks) > 0) {
            $pid = genpid($uid);
            $name = $person[$uid]['name'];
//            print "# $sql\n";
            print "mkag $uid $pid # $name ($accepted accepted, $fallbacks fallback)\n";
        }
    }
}
/*
 * Local Variables:
 * mode: C
 * c-file-style: "bsd"
 * indent-tabs-mode: nil
 * End:
 */
?>
