Exemple #1
0
    #JSON Array end
    $msg = "]\n }";
    echo $msg;
    echo PHP_EOL;
    ob_flush();
    flush();
    socket_close($socket);
}
/* actual logic */
error_reporting(0);
if (!empty($_POST)) {
    try {
        $queryObject = json_decode(stripslashes($_POST['query']));
        if ($queryObject->queryType == 'multiSketch') {
            foreach ($queryObject->query as $currentQuery) {
                //prepare image for Java
                if (isset($currentQuery->img)) {
                    $currentQuery->img = str_replace(' ', '+', $currentQuery->img);
                    $currentQuery->img = str_replace("\n", '', $currentQuery->img);
                }
            }
            $json = json_encode($queryObject);
            queryAPI($json);
        } else {
            $json = json_encode($queryObject);
            queryAPI($json);
        }
    } catch (Exception $e) {
        die('{ "type":"error", "msg" : "' . $e->getMessage() . '"}]}"');
    }
}
			array(
				'record_id'=>$record,
				'redcap_event_name'=>$data[0]['redcap_event_name'],
				$randomization_field=>$new_group['name'],
				$randomization_form.'_complete'=>2
			)
		)
	)
));
logIt('Upload 1: '. print_r($result, true), "DEBUG");

// Copy the data to the randomized event
$new_data = $data;
$new_data[0]['redcap_event_name']=$new_group['event'];
$result = queryAPI(array(
	'content'=>'record',
	'data'=>json_encode($new_data)
));
logIt('Upload 2: '. print_r($result, true), "DEBUG");





###### UTILITY FUNCTIONS

// Query the api - assumes json encoding
function queryAPI($params) {
	global $api_token, $api_url;
	
	// Assuming the following for all queries
	$params['token'] = $api_token;