$strRank .= ",<br/>";
        }
        $scoreSeparator = ",";
        $strRank .= "et la " . $contestant->schoolRank . getExpRank($contestant->schoolRank) . " place sur " . $contestant->nbStudentsSchool . " dans l'établissement";
    } else {
        if ($strRank != "") {
            $strRank = "et " . $strRank;
        } else {
            $scoreSeparator = ".";
        }
        $strExtraLines .= "<br/>";
    }
    if ($strRank != "") {
        $strRank .= ".";
    }
    if (preg_match('/^M\\./', $contestant->coordName)) {
        $title = "coordinateur";
    } else {
        $title = "coordinatrice";
    }
    $data = array("category" => $categoryNames[$contestant->level], "userName" => $contestant->userName, "score" => $contestant->score, "maxScore" => $contestant->maxScore, "scoreSeparator" => $scoreSeparator, "strRank" => $strRank, "date" => date("d/m/Y"), "coordinator" => $contestant->coordName . ", " . $title, "schoolName" => $contestant->schoolName, "schoolCity" => $contestant->schoolCity);
    $html = file_get_contents("certificate_template.html");
    foreach ($data as $key => $value) {
        $html = str_replace("{" . $key . "}", $value, $html);
    }
    return $html;
}
if (isset($_GET["schoolID_test"])) {
    genSchoolCertificates($_GET["schoolID_test"]);
    echo "done<br>";
}
/* Copyright (c) 2012 Association France-ioi, MIT License http://opensource.org/licenses/MIT */
require_once "../shared/common.php";
require_once "certiCommon.inc.php";
// Defines some global parameters
ini_set('display_errors', 1);
error_reporting(E_ALL);
ini_set('max_execution_time', -1);
// Get next request
$request = CertiGen::queueGetNext();
if (!$request) {
    echo "No request to process.\n";
    exit(0);
}
// Let's process the school
echo "Treating request {$request->ID} for school {$request->schoolID} ({$request->nbStudents} students).\n";
if (!CertiGen::queueStarted($request->ID)) {
    echo "Not starting\n";
    exit(0);
}
$time = microtime(true);
$nbStudents = genSchoolCertificates($request->schoolID);
$time = microtime(true) - $time;
echo "{$nbStudents} in {$time} seconds for school " . $request->schoolID . "\n";
if ($nbStudents > 0) {
    echo $time / $nbStudents . "s / student\n";
}
if (!CertiGen::queueFinished($request->ID)) {
    cleanSchool($request->schoolID);
    echo "Not finishing\n";
    exit(0);
}