Exemple #1
0
/**
 * Get a count of the results for a particular form.
 */
function form_results_count($id)
{
    return form\Results::query()->where('form_id', $id)->count();
}
Exemple #2
0
<?php

/**
 * Display a single result in full detail.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
if (!isset($_GET['id'])) {
    $this->redirect('/form/admin');
}
$res = new form\Results($_GET['id']);
if ($res->error) {
    $this->redirect('/form/admin');
}
$page->title = i18n_get('Browsing Result') . ': ' . $res->id;
$labels = $res->form_id()->labels();
$fields = (array) $res->results;
foreach ($fields as $k => $v) {
    if (is_array($v)) {
        $fields[$k] = join(', ', $v);
    }
}
echo $tpl->render('form/result', array('data' => $fields, 'submitted' => $res->ts, 'ip' => $res->ip, 'form' => $res->form_id, 'labels' => $labels));
Exemple #3
0
    // no form specified
    @error_log('no form specified');
    return;
}
$f = new form\Form((int) $id);
if ($f->error) {
    // form not found
    @error_log('form not found');
    return;
}
if ($f->submit()) {
    // handle form submission
    // unset csrf prevention token
    unset($_POST['_token_']);
    // save the results
    $r = new form\Results(array('form_id' => $id, 'ts' => gmdate('Y-m-d H:i:s'), 'ip' => $_SERVER['REMOTE_ADDR']));
    $r->results = $_POST;
    $r->put();
    // call any custom hooks
    $this->hook('form/submitted', array('form' => $id, 'values' => $_POST));
    foreach ($_POST as $k => $v) {
        if (is_array($v)) {
            $_POST[$k] = join(', ', $v);
        }
    }
    // if there's a redirect, we wait to exit after
    // all actions have been performed.
    $has_redirect = false;
    foreach ($f->actions as $action) {
        // handle action
        switch ($action->type) {
Exemple #4
0
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
if (!isset($_GET['id'])) {
    $this->redirect('/form/admin');
}
$f = new form\Form($_GET['id']);
if ($f->error) {
    $this->redirect('/form/admin');
}
$limit = 20;
$_GET['offset'] = isset($_GET['offset']) ? $_GET['offset'] : 0;
$results = form\Results::query()->where('form_id', $_GET['id'])->order('ts desc')->fetch($limit, $_GET['offset']);
$count = form\Results::query()->where('form_id', $_GET['id'])->count();
// determine which fields to display as columns
// as well as the column names
$labels = $f->labels();
if ($count > 0) {
    if (count($labels) === 1) {
        $field_one = current(array_keys($labels));
        $field_one_name = current(array_values($labels));
        $field_two_name = '';
        foreach ($results as $k => $v) {
            $res = $v->results;
            $results[$k]->field_one = is_array($res->{$field_one}) ? join(', ', $res->{$field_one}) : $res->{$field_one};
            $results[$k]->field_two = '';
        }
    } elseif (count($labels) > 1) {
        $keys = array_keys($labels);
Exemple #5
0
 */
if (!User::require_admin()) {
    $this->redirect('/admin');
}
if (!isset($_GET['id'])) {
    $this->redirect('/form/admin');
}
$f = new form\Form($_GET['id']);
if ($f->error) {
    $this->redirect('/form/admin');
}
$page->layout = false;
header('Cache-control: private');
header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename=' . preg_replace('/[^a-z0-9_-]+/', '-', strtolower($f->title)) . '-' . gmdate('Y-m-d') . '.csv');
$results = form\Results::query()->order('ts desc')->fetch_orig();
$labels = $f->labels();
echo 'Submitted,IP Address,' . join(',', $labels) . "\n";
foreach ($results as $row) {
    $sep = '';
    echo $row->ts . ',' . $row->ip . ',';
    $res = json_decode($row->results);
    foreach ($res as $k => $v) {
        if (is_array($v)) {
            $v = join(', ', $v);
        }
        $v = str_replace('"', '""', $v);
        if (strpos($v, ',') !== false) {
            $v = '"' . $v . '"';
        }
        $v = str_replace(array("\n", "\r"), array('\\n', '\\r'), $v);