try {
    //Register a new error handler to handle libxml specific errors
    $originalHandler = set_error_handler("libxml_error_handler");
    //Create a new DomDocument object and load the XML data into it
    $xmldata = new DomDocument();
    $xmldata->loadXML($data, LIBXML_NOBLANKS | LIBXML_NOCDATA | LIBXML_NOENT);
    //Remove whitespaces from the data
    purifyXML($xmldata->documentElement);
    //Restore the original error handler
    set_error_handler($originalHandler);
    //Retrieve the database configuration
    $dbconf = $config->Database;
    //Make sure the username is registered with this application
    $db = new Database($dbconf['host'], $dbconf['user'], $dbconf['pass'], $dbconf['name'], $dbconf['port']);
    //Store the data in the database
    $finaldata = $db->getSubjectFinalData($label);
    if ($finaldata['locked'] == '1') {
        $user = $db->searchUserByID($finaldata['aclID']);
        if (empty($user)) {
            $username = "******";
        } else {
            $username = $user['username'];
        }
        $date = $finaldata['datetimeModified'];
        ajax_error("Oops! Subject {$label} has been already locked by {$username} at {$date}.");
    } else {
        $db->storeFinalForm($label, $_SESSION['aclID'], $xmldata->saveXML(), $lock);
        $result = array("success" => 1, "subject" => $label);
    }
    ajax_result($result);
} catch (\Exception $e) {
Example #2
0
/** Returns the subject's final data as XML.
 * @param String $subjectLabel
 * @param Database $db
 * @return DomDocument The Subject data as XML
 */
function getSubjectFinalDataAsXML($subjectLabel, Database $db)
{
    if (empty($subjectLabel)) {
        throw new Exception("Empty subject label.");
    }
    //Retrieve the form data
    $result = $db->getSubjectFinalData($subjectLabel);
    if (empty($result) || !strlen($result['data'])) {
        return NULL;
    }
    //Register a new error handler to handle libxml specific errors
    $originalHandler = set_error_handler("libxml_error_handler");
    //Create an XML document to store all the data (properly)
    $xmldoc = new DomDocument();
    if (empty($result['data'])) {
        $result['data'] = '<result/>';
    }
    $xmldoc->loadXML($result['data']);
    $xmldoc->documentElement->setAttribute('locked', $result['locked']);
    $xmldoc->documentElement->setAttribute('subject', $subjectLabel);
    $xmldoc->documentElement->setAttribute('aclID', $result['aclID']);
    if (!empty($originalHandler)) {
        set_error_handler($originalHandler);
    }
    return $xmldoc;
}