Collection of themes/skins for the Fossil SCM

⌈⌋ branch:  Fossil Skins Extra


Artifact [13bb0bc0d4]

Artifact 13bb0bc0d4145f7cc24510eedf25edb622168e81:

  • Executable file extroot/survey — part of check-in [a08c7b5ce3] at 2021-09-19 10:16:52 on branch trunk — Add survey tbl display tool. (user: mario size: 1649)

#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: store
# category: database
# title: Survey submit
# description: Store simple POST form data into database survey_* table
# version: 0.2
# state: alpha
# config: -
#
# Requires a form like:
#
#    <action target="/ext/survey/SAMPLE" method=POST>
#        <input type=checkbox name=q1 value=1>
#        <input type=radio name=q2 value=1>
#        <input type=text name=q3>
#
# And will then populate a `survey_SAMPLE` table with JSON entries (no
# field expansion or anything).
#


#-- database (== fossil repo)
function db($sql="", $params=[]) {
    static $db;
    if (empty($db)) {
        $db = new PDO("sqlite:$_SERVER[FOSSIL_REPOSITORY]");
#$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    }
    if ($params) {
        $stmt = $db->prepare($sql);
        $stmt->execute($params);
        return $stmt->fetchAll(PDO::FETCH_ASSOC);
    }
    else {
        return $db->query($sql)->fetchAll();
    }
}


#-- insert
function store() {
    $tbl = preg_replace("/\W+/", "", basename($_SERVER["PATH_INFO"]));
    if (!$tbl) {
        die("No table name given /survey/NAME");
    }
    else {
        $json = json_encode($_POST);
        db("CREATE TABLE IF NOT EXISTS `survey_$tbl` (submitted TEXT, remote_addr TEXT, fields TEXT)");
#error_reporting(E_ALL);ini_set("display_errors", 1);
        db("INSERT INTO `survey_$tbl` (submitted, remote_addr, fields) VALUES (DATETIME('now'), ?, ?)", [$_SERVER["REMOTE_ADDR"], $json]);
        header("Location: /#thanks");
    }
}

#-- run
if (count($_POST)) {
    store();
}
else {
    die("Empty form");
}