public function loadRecords()
 {
     $params = array('fields' => array(REDCAP_FIRST_FIELD, getRF('username'), getRF('password'), getRF('email')));
     $result = RC::callApi($params);
     // Scan records for email and username matches and to set nextId
     $new_id = 1;
     $username_matches = $email_matches = array();
     foreach ($result as $idx => $record) {
         $id = $record[REDCAP_FIRST_FIELD];
         if (is_numeric($id) && $id >= $new_id) {
             $new_id = $id + 1;
         }
         //GUESS THE NEXT AUTOINCREME
         if (!$record[getRF('username')] || !$record[getRF('email')]) {
             continue;
         }
         if ($this->username == sanitize($record[getRF('username')])) {
             $username_matches[$id] = $record;
         }
         if ($this->email == sanitize($record[getRF('email')])) {
             $email_matches[$id] = $record;
         }
     }
     $this->next_user_id = $new_id;
     $this->username_matches = $username_matches;
     $this->email_matches = $email_matches;
     // print "RA:LOAD RECORDS<pre>".print_r($result,true)."</pre>";
 }
Example #2
0
<?php

require_once "../models/config.php";
//DATA POSSTING
if (isset($_REQUEST["ajax"]) && $_REQUEST["ajax"]) {
    if (isset($_REQUEST["surveycomplete"])) {
        $result = RC::callApi(array("hash" => $_REQUEST["hash"], "format" => "csv"), $custom_surveycomplet_API);
        print_r($result);
        exit;
    }
    //WRITE TO API
    //ADD OVERIDE PARAMETER
    $formdata = $_POST;
    $data = array();
    foreach ($_POST as $field_name => $value) {
        if ($value === 0) {
            $value = "0";
        }
        if ($value == "") {
            $value = NULL;
        }
        if (strpos("_complete", $field_name) > -1) {
            //CALL andy CUSTOM API FOR set SurveyComplete
        }
        $data[] = array("record" => $_SESSION[SESSION_NAME]["user"]->id, "redcap_event_name" => $_SESSION[SESSION_NAME]["survey_context"]["event"], "field_name" => $field_name, "value" => $value);
    }
    $result = RC::writeToApi($data, array("overwriteBehavior" => "overwite", "type" => "eav"));
    echo json_encode($result);
    exit;
}
//REDIRECT USERS THAT ARE NOT LOGGED IN
 public function loadUser()
 {
     global $redcap_field_map;
     // Strip off checkbox endings and reduce duplicates in case multiple different checkboxes options are being used
     // For example checkbox___1 and checkbox___2 become checkbox in the field array
     $fields = array_values(array_unique(preg_replace('/___\\d+/', '', $redcap_field_map)));
     $params = array('records' => array($this->user_id), 'fields' => $fields);
     $result = RC::callApi($params);
     //print "DEBUG: PARAMS: <pre>".print_r($params,true)."</pre>";
     //print "DEBUG: LOAD USER: <pre>".print_r($result,true)."</pre>";
     // THIS MESSES THINGS UP FOR multi ARM deals
     // if (count($result) != 1) {
     //    $this->errors[] = "Unable to load specified user (" . $this->user_id . ")";
     //    return false;
     // }
     // Load results into this object
     // $user = current($result);
     $user = $result[0];
     //logIt("Loaded User: "******"DEBUG");
     foreach ($redcap_field_map as $k => $v) {
         $this->{$k} = $user[$v];
     }
     //logIt("This: " . json_encode($this), "DEBUG");
     // TBD Sanitize any of the loaded variables?
     return true;
 }
function getUserAnswers($record_id = null, $fields = null)
{
    $extra_params = array('content' => 'record', 'records' => is_null($record_id) ? null : array($record_id), 'type' => "flat", 'fields' => $fields, 'exportSurveyFields' => true);
    $result = RC::callApi($extra_params);
    return $result;
}