Exemplo n.º 1
0
/**
 * List all forms for the dynamic objects dialog.
 */
function form_list_all()
{
    $res = form\Form::query('id, title')->order('title asc')->fetch_assoc('id', 'title');
    $out = array();
    foreach ($res as $k => $v) {
        $out[] = (object) array('key' => $k, 'value' => $v);
    }
    return $out;
}
Exemplo n.º 2
0
<?php

/**
 * Delete a form and its associated data.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
$f = new form\Form($_GET['id']);
if ($f->error) {
    $page->title = i18n_get('An Error Occurred');
    echo '<p>' . i18n_get('The requested form could not be found.') . '</p>';
    return;
}
if (!$f->remove()) {
    $page->title = i18n_get('An Error Occurred');
    echo '<p>' . i18n_get('Unable to delete the form.') . '</p>';
    return;
}
// also remove results
DB::execute('delete from results where form_id = ?', $_GET['id']);
$this->add_notification(i18n_get('Form deleted.'));
$this->redirect('/form/admin');
Exemplo n.º 3
0
Arquivo: add.php Projeto: Alm001/form
<?php

/**
 * Creates a new untitled form and forwards to /form/edit, the form builder.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
$f = new form\Form(array('title' => 'Untitled', 'message' => 'Please fill in the following information.', 'ts' => gmdate('Y-m-d H:i:s'), 'fields' => '[]', 'actions' => '[]', 'response_title' => 'Thank you', 'response_body' => 'Your information has been saved.'));
$f->put();
\Versions::add($f);
if (!$f->error) {
    $this->redirect('/form/edit?id=' . $f->id);
}
$page->title = i18n_get('An Error Occurred');
echo '<p>' . i18n_get('Unable to create a new form.') . '</p>';
Exemplo n.º 4
0
<?php

/**
 * Render a preview of a form based on the form ID. Usage:
 *
 *     /form/preview/form-id
 */
$page->layout = false;
$id = isset($this->params[0]) ? $this->params[0] : (isset($data['id']) ? $data['id'] : false);
if (!$id) {
    // 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;
}
// render the form
echo '<p class="section-header">' . i18n_get('Form preview') . '</p>';
echo '<h1>' . $f->title . '</h1>';
$o = $f->orig();
$o->failed = $f->failed;
echo $tpl->render('form/head', $o);
foreach ($f->field_list as $field) {
    if ($field->type == 'date') {
        if ($field->default_value == 'today') {
            $field->default_value = gmdate('Y-m-d');
        }
Exemplo n.º 5
0
<?php

/**
 * Returns a list of validation rules as a JSON object so that
 * `js/jquery.verify_values.js` can use the same validation rules
 * client-side that are used by `lib/Form.php` in server-side
 * validation.
 */
if (count($this->params) != 1) {
    die('Usage: /form/validator/form_id');
} elseif (!is_numeric($this->params[0])) {
    die('Invalid form name');
}
$f = new form\Form($this->params[0]);
if ($f->error) {
    die('Form not found');
}
$rules = $f->rules();
foreach ($rules as $k => $v) {
    if (is_array($v) && count($v) === 0) {
        unset($rules[$k]);
    }
}
$page->layout = false;
header('Content-Type: application/json');
echo json_encode($rules);
Exemplo n.º 6
0
<?php

/**
 * Browse a list of results for a specific form.
 */
$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};
Exemplo n.º 7
0
/**
 * Render a form based on the form ID. Usage:
 *
 *     {! form/form-id !}
 *
 * From the URL:
 *
 *     /form/form-id
 */
$id = isset($this->params[0]) ? $this->params[0] : (isset($data['id']) ? $data['id'] : false);
if (!$id) {
    // 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));
Exemplo n.º 8
0
<?php

/**
 * Admin page where you can edit forms, view results, and create new forms.
 */
$page->layout = 'admin';
if (!User::require_admin()) {
    $this->redirect('/admin');
}
require_once 'apps/form/lib/Functions.php';
$page->title = 'Forms';
$lock = new Lock();
$forms = form\Form::query()->order('title asc')->fetch_orig();
foreach ($forms as $k => $form) {
    $forms[$k]->locked = $lock->exists('Form', $form->id);
}
echo $tpl->render('form/admin', array('forms' => $forms));