Check-in [43bb630b42]
Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | crude survey tool (storage backend only) |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
43bb630b4297115696b98abd9debd5b9 |
User & Date: | mario 2021-09-19 09:31:17 |
Context
2021-09-19
| ||
10:16 | Add survey tbl display tool. check-in: a08c7b5ce3 user: mario tags: trunk | |
09:31 | crude survey tool (storage backend only) check-in: 43bb630b42 user: mario tags: trunk | |
2021-09-06
| ||
03:02 | Fix change detection check-in: 62d3073b30 user: mario tags: trunk | |
Changes
Added extroot/survey.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #!/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.1 # state: alpha # config: - # # Requires a form like: # # <action target="/extroot/survey/SAMPLE" method=POST> # <input type=checkbox name=q1> # <input type=radio name=q2> # <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]"); } 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 DATETIME, remote_addr, fields TEXT)"); db("INSERT INTO `survey_$tbl` (submitted, remote_addr, fields) VALUES (NOW(), ?, ?)", [$_SERVER["REMOTE_ADDR"], $json]); } } #-- run if (count($_POST)) { store(); } else { die("Empty form"); } |