#!/usr/bin/php -q
<?php
// our Serial Number
$GLOBALS['SERIAL_NUMBER'] = "UNKNOWN";

// change to web server root to load scripts
chdir("/var/www");
// access to config file
/** @noinspection PhpIncludeInspection */
require_once "src/foundation/class.siteconfig.php";
// db access; uses config file
/** @noinspection PhpIncludeInspection */
require_once "src/foundation/class.common.php";
// access global conig
/** @noinspection PhpIncludeInspection */
require_once "src/class/class.globalconfig.php";

function init() {
    $oConf = new GlobalConfig('en');
    $settings = $oConf->GetParams(array(143));
    $GLOBALS['SERIAL_NUMBER'] = isset($settings[143]) ? $settings[143]['str_val'] : 'UNKNOWN';
}

function writeSerial() {
    fwrite($GLOBALS['stdout'], $GLOBALS['SERIAL_NUMBER'] . "\n");
}

function main(/** @noinspection PhpUnusedParameterInspection */$argc, $argv) {
    writeSerial();
    exit(0);
}

// supported STDIN/OUT/ERR syntax for php version 4.3 till 5.3
$stderr = fopen('php://stderr', 'w');
$stdout = fopen('php://stdout', 'w');
// fetch our serial number
init();
// $argc, $argv are filled in by the CLI engine and defined as globals
main($argc, $argv);
