Example #1
0
<?php

require_once '../sc_data_recording.php';
date_default_timezone_set('Europe/London');
// $sc_dr = new SC_Data_Recording('test_survey');
$survey_id = 'sc_test_survey';
$arr_response = array('q_one' => 'Tom', 'q_two' => 'likes', 'q_three' => array('chocolate', 'roast lamb', 'cheese', 'pork pies'));
$db = array('host' => 'localhost', 'name' => 'sc_test', 'user' => 'root', 'pass' => '');
$local = TRUE;
$created_time = strtotime('-10 minutes');
$device_id = 'SC Test Page';
$rid = SC_Data_Recording::to_database($survey_id, $arr_response, $db, $local, $created_time, $device_id);
echo 'Response recorded: ' . $rid;
Example #2
0
<?php

require_once '../sc_data_recording.php';
$db = array('host' => 'localhost', 'name' => 'sc_surveys', 'user' => 'root', 'pass' => '');
SC_Data_Recording::create_database($db, TRUE);
echo 'Database created';
Example #3
0
            //Response has already been noted, so this must be a duplicate submission
            $duplicate_response = TRUE;
            break;
        }
    }
    //Store this urid
    $_SESSION['urids'][] = $response['h_unique_response_id'];
} else {
    //Create urid library and store this urid for future testing
    $_SESSION['urids'] = array($response['h_unique_response_id']);
}
//Save the response
if (!$duplicate_response) {
    //Complete response with system data
    $response['h_finish_time'] = isset($_SESSION['wrapper']['date']) ? $_SESSION['wrapper']['date'] : time();
    $response['h_duration'] = isset($response['h_start_time']) && $response['h_start_time'] > 0 ? (string) ((int) $response['h_finish_time'] - (int) $response['h_start_time']) : '';
    //Set database to local or remote
    if ($config['isOffline']) {
        $db = $dbs['local'];
        $local = TRUE;
    } else {
        $db = $dbs['remote'];
        $local = FALSE;
    }
    //Save the response to the database
    $response_id = SC_Data_Recording::to_database($sid, $response, $db, $local, $response['h_finish_time'], $did);
}
unset($_SESSION['wrapper']['date']);
//Load thank you page
header('Location:../?pagetype=thankyou');
exit;
Example #4
0
<?php

date_default_timezone_set('Europe/London');
require_once '../config/dbs.php';
require_once '../-functions.php';
require_once '../toolkit/sc_data_recording.php';
if (isset($_GET['local'])) {
    if ($_GET['local'] === 'true') {
        # Create local database
        SC_Data_Recording::create_database($dbs['local'], TRUE);
        exit('Local database created');
    }
    if ($_GET['local'] === 'false') {
        # Create remote database
        SC_Data_Recording::create_database($dbs['remote'], FALSE);
        exit('Remote database created');
    }
    throw new Exception('set "local" to "true" or "false"');
}
throw new Exception('run again with querystring var "local" set to "true" or "false"');
Example #5
0
<?php

require_once '../sc_data_recording.php';
$arr_ids = array('1379937770-test_questions-unknown device', 'response_c', '1379937848-test_languages-test');
$db = array('host' => 'elephant.dns-systems.net', 'port' => 3306, 'name' => 'elephant_sc_test', 'user' => 'elephant_sc_test', 'pass' => 'EKt35tdb');
$local = TRUE;
SC_Data_Recording::mark_as_downloaded($arr_ids, $db, $local);
echo 'Responses marked as downloaded.';
Example #6
0
 /**
  * Marks database responses as downloaded
  * @static
  * @param array $arr_ids response ids to mark
  * @param array $db 'SC Database array'
  * @param bool $local local database or not?
  */
 public static function mark_as_downloaded($arr_ids, $db, $local = FALSE)
 {
     // Connect to the database
     try {
         $dsn = SC_Data_Recording::getDSN($db);
         $pdo = new PDO($dsn, $db['user'], $db['pass']);
         $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         exit('Could not connect to database');
     }
     //Update response status to flag as downloaded
     $qmarks = array_fill(0, count($arr_ids), '?');
     $sql = "UPDATE `responses` SET `Status` = ?, `Exported` = ? WHERE `ResponseID` IN (" . implode(", ", $qmarks) . ")";
     $params = array(SC_Data_Recording::DB_STATUS_DOWNLOADED, time());
     foreach ($arr_ids as $id) {
         $params[] = $id;
     }
     try {
         $stmt = $pdo->prepare($sql);
         $stmt->execute($params);
     } catch (PDOException $e) {
         exit('Responses update error. ' . $e->getMessage());
     }
     $pdo = NULL;
 }
Example #7
0
<?php

date_default_timezone_set('Europe/London');
require_once '../config/dbs.php';
require_once '../-functions.php';
require_once '../toolkit/sc_data_recording.php';
if (session_id() == '') {
    session_start();
}
set_time_limit(180);
$status = SC_Data_Recording::upload_latest_responses($dbs['local'], $dbs['remote']);
exit('Uploaded ' . $status['uploaded'] . ' of ' . $status['total'] . ' responses');
Example #8
0
<?php

require_once '../sc_data_recording.php';
$db = array('local' => array('host' => 'localhost', 'name' => 'sc_surveys', 'user' => 'root', 'pass' => ''), 'remote' => array('host' => 'elephant.dns-systems.net', 'port' => 3306, 'name' => 'elephant_sc_test', 'user' => 'elephant_sc_test', 'pass' => 'EKt35tdb'));
$result = SC_Data_Recording::upload_latest_responses($db['local'], $db['remote']);
var_dump($result);
Example #9
0
<?php

require_once '../sc_data_recording.php';
$survey_id = 'test_questions';
$db = array('host' => 'elephant.dns-systems.net', 'port' => 3306, 'name' => 'elephant_sc_test', 'user' => 'elephant_sc_test', 'pass' => 'EKt35tdb');
$local = FALSE;
$data = SC_Data_Recording::from_database($survey_id, $db, $local);
var_dump($data);