$xml_upload_hash = sha1($composite_xml);
$stmt = phoromatic_server::$db->prepare('INSERT INTO phoromatic_results (AccountID, SystemID, UploadID, ScheduleID, BenchmarkTicketID, Trigger, UploadTime, Title, Description, SystemCount, ResultCount, DisplayStatus, XmlUploadHash, ComparisonHash, ElapsedTime, PPRID) VALUES (:account_id, :system_id, :upload_id, :schedule_id, :benchmark_ticket_id, :trigger, :upload_time, :title, :description, :system_count, :result_count, :display_status, :xml_upload_hash, :comparison_hash, :elapsed_time, :pprid)');
$stmt->bindValue(':account_id', ACCOUNT_ID);
$stmt->bindValue(':system_id', SYSTEM_ID);
$stmt->bindValue(':upload_id', $upload_id);
$stmt->bindValue(':schedule_id', $SCHEDULE_ID);
$stmt->bindValue(':benchmark_ticket_id', $BENCHMARK_TICKET_ID);
$stmt->bindValue(':trigger', $TRIGGER_STRING);
$stmt->bindValue(':upload_time', $upload_time);
$stmt->bindValue(':title', sqlite_escape_string($result_file->get_title()));
$stmt->bindValue(':description', sqlite_escape_string($result_file->get_description()));
$stmt->bindValue(':system_count', $result_file->get_system_count());
$stmt->bindValue(':result_count', $result_file->get_test_count());
$stmt->bindValue(':display_status', 1);
$stmt->bindValue(':xml_upload_hash', $xml_upload_hash);
$stmt->bindValue(':comparison_hash', $result_file->get_contained_tests_hash(false));
$stmt->bindValue(':elapsed_time', empty($ELAPSED_TIME) || !is_numeric($ELAPSED_TIME) || $ELAPSED_TIME < 0 ? 0 : $ELAPSED_TIME);
$stmt->bindValue(':pprid', phoromatic_server::compute_pprid(ACCOUNT_ID, SYSTEM_ID, $upload_time, $xml_upload_hash));
$result = $stmt->execute();
//echo phoromatic_server::$db->lastErrorMsg();
$result_directory = phoromatic_server::phoromatic_account_result_path(ACCOUNT_ID, $upload_id);
pts_file_io::mkdir($result_directory);
//phoromatic_add_activity_stream_event('result', $upload_id, 'uploaded');
file_put_contents($result_directory . 'composite.xml', $composite_xml);
if ($SYSTEM_LOGS_ZIP != null && $SYSTEM_LOGS_HASH != null) {
    if (sha1($SYSTEM_LOGS_ZIP) == $SYSTEM_LOGS_HASH) {
        $system_logs_zip = $result_directory . 'system-logs.zip';
        file_put_contents($system_logs_zip, base64_decode($_POST['system_logs_zip']));
        /*if(filesize($system_logs_zip) > 2097152)
        		{
        			unlink($system_logs_zip);