Example #1
0
require_once "NRG/Configuration.php";
require_once '../database.php';
//Require data entry privileges
setClearanceLevel(30);
//Check for errors
if (empty($_POST) || empty($_POST['subjectid'])) {
    ajax_error('Invalid request.');
}
$subjectid = trim($_POST['subjectid']);
if (empty($subjectid)) {
    ajax_error('Invalid Subject ID.');
}
if (!preg_match('/^[A-Za-z0-9]+$/', $subjectid)) {
    ajax_error('The Subject ID you have entered contains invalid characters.');
}
//Connect to the database
try {
    $config = new \NRG\Configuration(CONFIG_FILE);
    $dbconf = $config->Database;
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    //Verify the subject isn't locked
    if ($db->isSubjectLocked($subjectid)) {
        ajax_error('Sorry, this subject has been locked. No data entry is allowed for locked subjects.');
    }
    $session = $db->createSession($subjectid, $_SESSION['aclID']);
    $result = array("success" => 1, "session" => $session['label']);
    ajax_result($result);
} catch (Exception $e) {
    error_log($e->getMessage(), 0);
    ajax_error('An internal server error has occured. Please try again later.' . $e->getMessage());
}
Example #2
0
$labels = explode(",", trim(strtoupper($_REQUEST['label'])));
if (count($labels) > MAX_LABELS) {
    ajax_error("Your request has exceeded the maximum number of subject labels allowed (" . MAX_LABELS . ")");
}
$xml = "";
$result = array("success" => 1, "count" => 0, "data" => array());
try {
    $config = new \NRG\Configuration("../config.ini.php");
    $dbconfig = $config->Database;
    $db = new Database($dbconfig['host'], $dbconfig['user'], $dbconfig['pass'], $dbconfig['name']);
    if (!$db) {
        throw new Exception("Couldn't connect to the database.");
    }
    foreach ($labels as $subjectLabel) {
        //Skip subjects that were not locked
        if (!$db->isSubjectLocked($subjectLabel)) {
            continue;
        }
        $xml = NULL;
        $xml = getSubjectFinalDataAsXML($subjectLabel, $db);
        if ($xml) {
            $converted_data = convertFinalDataToArray($xml, array('DATA_LABEL', 'RESP'));
            applyHQHack($converted_data);
            applyDEMHack($converted_data);
            $result['data'][$subjectLabel] = $converted_data;
            ++$result['count'];
        }
    }
} catch (Exception $e) {
    ajax_error($e->getMessage());
}