Example #1
0
 public static function resetConnection()
 {
     if (self::$_connection !== null && self::$_connection->isConnected()) {
         self::$_connection->disconnect();
         self::$_connection = self::createConnection();
     }
 }
Example #2
0
    //ADD OVERIDE PARAMETER
    $formdata = $_POST;
    $data = array();
    foreach ($_POST as $field_name => $value) {
        if ($value === 0) {
            $value = "0";
        }
        if ($value == "") {
            $value = NULL;
        }
        $field_name = $redcap_field_map[$field_name];
        //SET IT IN THE SESSION
        $_SESSION[SESSION_NAME]["user"]->{$field_name} = $value;
        $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($data);
    exit;
}
//REDIRECT USERS THAT ARE NOT LOGGED IN
if (!isUserLoggedIn()) {
    $destination = $websiteUrl . "login.php";
    header("Location: " . $destination);
    exit;
} else {
    //if they are logged in and active
    //find survey completion and go there?
    // GET SURVEY LINKS
    include "../models/inc/surveys.php";
}
$shownavsmore = true;
Example #3
0
 function testMultiExecContext_CheckAndSet_Discard()
 {
     $client = RC::getConnection();
     $client->flushdb();
     $client->set('foo', 'bar');
     $options = array('watch' => 'foo', 'cas' => true);
     $replies = $client->multiExec($options, function ($tx) {
         $tx->watch('foobar');
         $foo = $tx->get('foo');
         $tx->multi();
         $tx->set('foobar', $foo);
         $tx->discard();
         $tx->mget('foo', 'foobar');
     });
     $this->assertInternalType('array', $replies);
     $this->assertEquals(array(array('bar', null)), $replies);
     $hijack = true;
     $client->set('foo', 'bar');
     $client2 = RC::getConnection(true);
     $options = array('watch' => 'foo', 'cas' => true, 'retry' => 1);
     $replies = $client->multiExec($options, function ($tx) use($client2, &$hijack) {
         $foo = $tx->get('foo');
         $tx->multi();
         $tx->set('foobar', $foo);
         $tx->discard();
         if ($hijack) {
             $hijack = false;
             $client2->set('foo', 'hijacked!');
         }
         $tx->mget('foo', 'foobar');
     });
     $this->assertInternalType('array', $replies);
     $this->assertEquals(array(array('hijacked!', null)), $replies);
 }
Example #4
0
 public static function getConnectionParametersArgumentsString($arguments = null)
 {
     // TODO: must be improved
     $args = $arguments !== null ? $arguments : RC::getConnectionParametersArgumentsArray();
     $paramsString = "redis://{$args['host']}:{$args['port']}/";
     $paramsString .= "?connection_timeout={$args['connection_timeout']}&read_write_timeout={$args['read_write_timeout']}";
     $paramsString .= "&database={$args['database']}&password={$args['password']}&alias={$args['alias']}";
     return $paramsString;
 }
Example #5
0
 public static function getConnectionParametersArgumentsString($arguments = null)
 {
     // TODO: must be improved
     $args = $arguments ?: RC::getConnectionParametersArgumentsArray();
     $paramsString = "redis://{$args['host']}:{$args['port']}/?";
     unset($args['host']);
     unset($args['port']);
     foreach ($args as $k => $v) {
         $paramsString .= "{$k}={$v}&";
     }
     return $paramsString;
 }
Example #6
0
 function testSort()
 {
     $unorderedList = RC::pushTailAndReturn($this->redis, 'unordered', array(2, 100, 3, 1, 30, 10));
     // without parameters
     $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->sort('unordered'));
     // with parameter ASC/DESC
     $this->assertEquals(array(100, 30, 10, 3, 2, 1), $this->redis->sort('unordered', array('sort' => 'desc')));
     // with parameter LIMIT
     $this->assertEquals(array(1, 2, 3), $this->redis->sort('unordered', array('limit' => array(0, 3))));
     $this->assertEquals(array(10, 30), $this->redis->sort('unordered', array('limit' => array(3, 2))));
     // with parameter ALPHA
     $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true)));
     // with combined parameters
     $this->assertEquals(array(30, 10, 3, 2), $this->redis->sort('unordered', array('alpha' => false, 'sort' => 'desc', 'limit' => array(1, 4))));
     // with parameter ALPHA
     $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true)));
     // with parameter STORE
     $this->assertEquals(count($unorderedList), $this->redis->sort('unordered', array('store' => 'ordered')));
     $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->lrange('ordered', 0, -1));
     // with parameter GET
     $this->redis->rpush('uids', 1003);
     $this->redis->rpush('uids', 1001);
     $this->redis->rpush('uids', 1002);
     $this->redis->rpush('uids', 1000);
     $sortget = array('uid:1000' => 'foo', 'uid:1001' => 'bar', 'uid:1002' => 'hoge', 'uid:1003' => 'piyo');
     $this->redis->mset($sortget);
     $this->assertEquals(array_values($sortget), $this->redis->sort('uids', array('get' => 'uid:*')));
     // wrong type
     RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, p_anon("\$test", "\n            \$test->redis->set('foo', 'bar');\n            \$test->redis->sort('foo');\n        "));
 }
 public function createNewUser($pass, $verifymail = true)
 {
     if (self::usernameExists()) {
         $this->error = "Error creating user (CODE 001)";
         // Don't create a user if they already exist!
         return false;
     }
     if (empty($pass)) {
         $this->error = "Error creating user (CODE 002)";
         // Missing password
         return false;
     }
     // Salt and Hash password
     //$salt = generateRandomString(25, true);
     $password_salt_hash = generateHash($pass);
     //logIt("Hashing $pass with $salt to yield $password_hash","DEBUG");
     $data = array(REDCAP_FIRST_FIELD => $this->next_user_id, getRF('username') => $this->username, getRF('password') => $password_salt_hash, getRF('firstname') => ucfirst($this->firstname), getRF('lastname') => $this->lastname, getRF('zip') => $this->zip, getRF('city') => $this->city, getRF('state') => $this->state, getRF('age') => $this->age, getRF('email') => $this->email, getRF('created_ts') => date('Y-m-d H:i:s'));
     // Add event if longitudinal
     if (REDCAP_PORTAL_EVENT !== NULL) {
         $data['redcap_event_name'] = REDCAP_PORTAL_EVENT;
     }
     logIt("CREATE NEW USER WITH DATA:" . print_r($data, true), "DEBUG");
     $result = RC::writeToApi($data, array('returnContent' => 'ids'));
     $new_user_id = is_array($result) ? current($result) : null;
     if (is_numeric($new_user_id)) {
         $this->new_user_id = $new_user_id;
         if ($verifymail) {
             $newuser = new RedcapPortalUser($new_user_id);
             $newuser->createEmailToken();
             $newuser->emailEmailToken();
         }
     } else {
         logIt("Error creating new user: "******"ERROR");
         $this->error = "Error creating user via API";
     }
     logIt("CREATE NEW USER RESULT:" . json_encode($result), "DEBUG");
     return $new_user_id;
 }
Example #8
0
 function testMultiExecBlock_Watch()
 {
     $client1 = RC::getConnection();
     $client2 = RC::getConnection(true);
     $client1->flushdb();
     RC::testForAbortedMultiExecException($this, function () use($client1, $client2) {
         $client1->multiExec(array('watch' => 'sentinel'), function ($multi) use($client2) {
             $multi->set('sentinel', 'client1');
             $multi->get('sentinel');
             $client2->set('sentinel', 'client2');
         });
     });
     $this->assertEquals('client2', $client1->get('sentinel'));
 }
 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;
 }
Example #10
0
 function testCommandPipeline_Flush()
 {
     $client = RC::getConnection();
     $client->flushdb();
     $pipe = $client->pipeline();
     $pipe->set('foo', 'bar')->set('hoge', 'piyo');
     $pipe->flushPipeline();
     $pipe->ping()->mget(array('foo', 'hoge'));
     $replies = $pipe->execute();
     $this->assertType('array', $replies);
     $this->assertEquals(4, count($replies));
     $this->assertEquals('bar', $replies[3][0]);
     $this->assertEquals('piyo', $replies[3][1]);
 }
Example #11
0
 function testMultiExecBlock_CheckAndSet_Discard()
 {
     $client = RC::getConnection();
     $client->flushdb();
     $client->set('foo', 'bar');
     $options = array('watch' => 'foo', 'cas' => true);
     $replies = $client->multiExec($options, p_anon("\$tx", "\n            \$tx->watch('foobar');\n            \$foo = \$tx->get('foo');\n            \$tx->multi();\n            \$tx->set('foobar', \$foo);\n            \$tx->discard();\n            \$tx->mget('foo', 'foobar');\n        "));
     $this->assertInternalType('array', $replies);
     $this->assertEquals(array(array('bar', null)), $replies);
     $hijack = true;
     $client->set('foo', 'bar');
     $options = array('watch' => 'foo', 'cas' => true, 'retry' => 1);
     $replies = $client->multiExec($options, p_anon("\$tx", "\n            \$client2 = RC::getConnection(true);\n            \$hijack = \$client2->get('foo') !== 'hijacked';\n            \$foo = \$tx->get('foo');\n            \$tx->multi();\n            \$tx->set('foobar', \$foo);\n            \$tx->discard();\n            if (\$hijack) {\n                \$client2->set('foo', 'hijacked!');\n            }\n            \$tx->mget('foo', 'foobar');\n        "));
     $this->assertInternalType('array', $replies);
     $this->assertEquals(array(array('hijacked!', null)), $replies);
 }
Example #12
0
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;
}
 function testSort()
 {
     $unorderedList = RC::pushTailAndReturn($this->redis, 'unordered', array(2, 100, 3, 1, 30, 10));
     // without parameters
     $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->sort('unordered'));
     // with parameter ASC/DESC
     $this->assertEquals(array(100, 30, 10, 3, 2, 1), $this->redis->sort('unordered', array('sort' => 'desc')));
     // with parameter LIMIT
     $this->assertEquals(array(1, 2, 3), $this->redis->sort('unordered', array('limit' => array(0, 3))));
     $this->assertEquals(array(10, 30), $this->redis->sort('unordered', array('limit' => array(3, 2))));
     // with parameter ALPHA
     $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true)));
     // with combined parameters
     $this->assertEquals(array(30, 10, 3, 2), $this->redis->sort('unordered', array('alpha' => false, 'sort' => 'desc', 'limit' => array(1, 4))));
     // with parameter ALPHA
     $this->assertEquals(array(1, 10, 100, 2, 3, 30), $this->redis->sort('unordered', array('alpha' => true)));
     // with parameter STORE
     $this->assertEquals(count($unorderedList), $this->redis->sort('unordered', array('store' => 'ordered')));
     $this->assertEquals(array(1, 2, 3, 10, 30, 100), $this->redis->listRange('ordered', 0, -1));
     // wront type
     RC::testForServerException($this, RC::EXCEPTION_WRONG_TYPE, function ($test) {
         $test->redis->set('foo', 'bar');
         $test->redis->sort('foo');
     });
 }
Example #14
0
 function testMultiExecBlock_RetryOnServerAbort()
 {
     $client1 = RC::getConnection();
     $client1->flushdb();
     $retry = 3;
     $thrownException = null;
     try {
         $options = array('watch' => 'sentinel', 'retry' => $retry);
         $client1->multiExec($options, p_anon("\$tx", "\n                \$tx->set('sentinel', 'client1');\n                \$tx->get('sentinel');\n                \$client2 = RC::getConnection(true);\n                \$client2->incr('attempts');\n                \$client2->set('sentinel', 'client2');\n            "));
     } catch (Predis_AbortedMultiExec $exception) {
         $thrownException = $exception;
     }
     $this->assertType('Predis_AbortedMultiExec', $thrownException);
     $this->assertEquals('The current transaction has been aborted by the server', $thrownException->getMessage());
     $this->assertEquals('client2', $client1->get('sentinel'));
     $this->assertEquals($retry + 1, $client1->get('attempts'));
     $client1->del('attempts', 'sentinel');
     $thrownException = null;
     try {
         $options = array('watch' => 'sentinel', 'cas' => true, 'retry' => $retry);
         $client1->multiExec($options, p_anon("\$tx", "\n                \$tx->incr('attempts');\n                \$tx->multi();\n                \$tx->set('sentinel', 'client1');\n                \$tx->get('sentinel');\n                \$client2 = RC::getConnection(true);\n                \$client2->set('sentinel', 'client2');\n            "));
     } catch (Predis_AbortedMultiExec $exception) {
         $thrownException = $exception;
     }
     $this->assertType('Predis_AbortedMultiExec', $thrownException);
     $this->assertEquals('The current transaction has been aborted by the server', $thrownException->getMessage());
     $this->assertEquals('client2', $client1->get('sentinel'));
     $this->assertEquals($retry + 1, $client1->get('attempts'));
 }