Collection of themes/skins for the Fossil SCM

⌈⌋ ⎇ branch:  Fossil Skins Extra


Hex Artifact Content

Artifact 422fa0c28a75ba6ab843c3a44f2835e6571d7764:

  • Executable file extroot/survey — part of check-in [0e67fdb36b] at 2021-10-20 05:59:00 on branch trunk — support for #access: flag (user: mario size: 1534)

0000: 23 21 2f 75 73 72 2f 62 69 6e 2f 70 68 70 2d 63  #!/usr/bin/php-c
0010: 67 69 20 2d 64 63 67 69 2e 66 6f 72 63 65 5f 72  gi -dcgi.force_r
0020: 65 64 69 72 65 63 74 3d 30 0a 3c 3f 70 68 70 0a  edirect=0.<?php.
0030: 23 20 65 6e 63 6f 64 69 6e 67 3a 20 75 74 66 2d  # encoding: utf-
0040: 38 0a 23 20 61 70 69 3a 20 63 67 69 0a 23 20 74  8.# api: cgi.# t
0050: 79 70 65 3a 20 73 74 6f 72 65 0a 23 20 63 61 74  ype: store.# cat
0060: 65 67 6f 72 79 3a 20 64 61 74 61 62 61 73 65 0a  egory: database.
0070: 23 20 74 69 74 6c 65 3a 20 53 75 72 76 65 79 20  # title: Survey 
0080: 73 75 62 6d 69 74 0a 23 20 64 65 73 63 72 69 70  submit.# descrip
0090: 74 69 6f 6e 3a 20 53 74 6f 72 65 20 61 72 62 69  tion: Store arbi
00a0: 74 72 61 72 79 20 50 4f 53 54 20 66 6f 72 6d 20  trary POST form 
00b0: 64 61 74 61 20 69 6e 74 6f 20 61 20 73 75 72 76  data into a surv
00c0: 65 79 5f 2a 20 74 61 62 6c 65 0a 23 20 76 65 72  ey_* table.# ver
00d0: 73 69 6f 6e 3a 20 30 2e 32 0a 23 20 73 74 61 74  sion: 0.2.# stat
00e0: 65 3a 20 61 6c 70 68 61 0a 23 20 63 6f 6e 66 69  e: alpha.# confi
00f0: 67 3a 20 2d 0a 23 20 61 63 63 65 73 73 3a 20 70  g: -.# access: p
0100: 75 62 6c 69 63 0a 23 0a 23 20 52 65 71 75 69 72  ublic.#.# Requir
0110: 65 73 20 61 20 66 6f 72 6d 20 6c 69 6b 65 3a 0a  es a form like:.
0120: 23 0a 23 20 20 20 20 3c 61 63 74 69 6f 6e 20 74  #.#    <action t
0130: 61 72 67 65 74 3d 22 2f 65 78 74 2f 73 75 72 76  arget="/ext/surv
0140: 65 79 2f 53 41 4d 50 4c 45 22 20 6d 65 74 68 6f  ey/SAMPLE" metho
0150: 64 3d 50 4f 53 54 3e 0a 23 20 20 20 20 20 20 20  d=POST>.#       
0160: 20 3c 69 6e 70 75 74 20 74 79 70 65 3d 63 68 65   <input type=che
0170: 63 6b 62 6f 78 20 6e 61 6d 65 3d 71 31 20 76 61  ckbox name=q1 va
0180: 6c 75 65 3d 31 3e 0a 23 20 20 20 20 20 20 20 20  lue=1>.#        
0190: 3c 69 6e 70 75 74 20 74 79 70 65 3d 72 61 64 69  <input type=radi
01a0: 6f 20 6e 61 6d 65 3d 71 32 20 76 61 6c 75 65 3d  o name=q2 value=
01b0: 31 3e 0a 23 20 20 20 20 20 20 20 20 3c 69 6e 70  1>.#        <inp
01c0: 75 74 20 74 79 70 65 3d 74 65 78 74 20 6e 61 6d  ut type=text nam
01d0: 65 3d 71 33 3e 0a 23 20 20 20 20 20 20 20 20 3c  e=q3>.#        <
01e0: 69 6e 70 75 74 20 74 79 70 65 3d 73 75 62 6d 69  input type=submi
01f0: 74 3e 0a 23 20 20 20 20 3c 61 20 68 72 65 66 3d  t>.#    <a href=
0200: 22 2f 65 78 74 2f 73 75 72 76 65 79 5f 73 75 6d  "/ext/survey_sum
0210: 2f 53 41 4d 50 4c 45 22 3e 73 65 65 20 72 65 73  /SAMPLE">see res
0220: 75 6c 74 73 e2 80 a6 3c 2f 61 3e 0a 23 0a 23 20  ults…</a>.#.# 
0230: 41 6e 64 20 77 69 6c 6c 20 74 68 65 6e 20 70 6f  And will then po
0240: 70 75 6c 61 74 65 20 61 20 60 73 75 72 76 65 79  pulate a `survey
0250: 5f 53 41 4d 50 4c 45 60 20 74 61 62 6c 65 20 77  _SAMPLE` table w
0260: 69 74 68 20 4a 53 4f 4e 20 65 6e 74 72 69 65 73  ith JSON entries
0270: 20 28 6e 6f 0a 23 20 66 69 65 6c 64 20 65 78 70   (no.# field exp
0280: 61 6e 73 69 6f 6e 20 6f 72 20 61 6e 79 74 68 69  ansion or anythi
0290: 6e 67 29 2e 20 44 6f 65 73 20 61 6c 6c 6f 77 20  ng). Does allow 
02a0: 66 6f 72 20 61 72 72 61 79 20 61 6e 64 20 74 65  for array and te
02b0: 78 74 20 73 74 6f 72 61 67 65 2e 0a 23 20 57 68  xt storage..# Wh
02c0: 65 72 65 61 73 20 60 73 75 72 76 65 79 5f 73 75  ereas `survey_su
02d0: 6d 60 20 77 69 6c 6c 20 6f 6e 6c 79 20 73 68 6f  m` will only sho
02e0: 77 20 63 6f 75 6e 74 61 62 6c 65 20 65 6e 74 72  w countable entr
02f0: 69 65 73 2e 20 4d 6f 72 65 20 64 65 74 61 69 6c  ies. More detail
0300: 65 64 0a 23 20 61 6e 61 6c 79 73 69 73 20 68 61  ed.# analysis ha
0310: 73 20 74 6f 20 62 65 20 64 6f 6e 65 20 6d 61 6e  s to be done man
0320: 75 61 6c 6c 79 2e 0a 23 0a 0a 69 6e 63 6c 75 64  ually..#..includ
0330: 65 28 22 2e 2f 66 6f 73 73 69 6c 5f 63 6f 6d 6d  e("./fossil_comm
0340: 6f 6e 2e 70 68 70 22 29 3b 0a 64 65 66 69 6e 65  on.php");.define
0350: 28 22 52 58 5f 54 42 4c 22 2c 20 22 2f 5e 28 5c  ("RX_TBL", "/^(\
0360: 77 2b 7c 74 61 62 6c 65 32 7c 6e 61 6d 65 29 24  w+|table2|name)$
0370: 2f 22 29 3b 20 20 20 2f 2f 20 61 6c 6c 6f 77 65  /");   // allowe
0380: 64 20 73 75 72 76 65 79 5f 24 74 62 6c 20 6e 61  d survey_$tbl na
0390: 6d 65 73 0a 0a 0a 0a 23 2d 2d 20 69 6e 73 65 72  mes....#-- inser
03a0: 74 0a 66 75 6e 63 74 69 6f 6e 20 73 74 6f 72 65  t.function store
03b0: 28 24 74 62 6c 29 20 7b 0a 20 20 20 20 24 6a 73  ($tbl) {.    $js
03c0: 6f 6e 20 3d 20 6a 73 6f 6e 5f 65 6e 63 6f 64 65  on = json_encode
03d0: 28 24 5f 50 4f 53 54 29 3b 0a 20 20 20 20 64 62  ($_POST);.    db
03e0: 28 22 43 52 45 41 54 45 20 54 41 42 4c 45 20 49  ("CREATE TABLE I
03f0: 46 20 4e 4f 54 20 45 58 49 53 54 53 20 60 73 75  F NOT EXISTS `su
0400: 72 76 65 79 5f 24 74 62 6c 60 20 28 73 75 62 6d  rvey_$tbl` (subm
0410: 69 74 74 65 64 20 54 45 58 54 2c 20 72 65 6d 6f  itted TEXT, remo
0420: 74 65 5f 61 64 64 72 20 54 45 58 54 2c 20 66 69  te_addr TEXT, fi
0430: 65 6c 64 73 20 54 45 58 54 29 22 29 3b 0a 20 20  elds TEXT)");.  
0440: 20 20 64 62 28 22 49 4e 53 45 52 54 20 49 4e 54    db("INSERT INT
0450: 4f 20 60 73 75 72 76 65 79 5f 24 74 62 6c 60 20  O `survey_$tbl` 
0460: 28 73 75 62 6d 69 74 74 65 64 2c 20 72 65 6d 6f  (submitted, remo
0470: 74 65 5f 61 64 64 72 2c 20 66 69 65 6c 64 73 29  te_addr, fields)
0480: 20 56 41 4c 55 45 53 20 28 44 41 54 45 54 49 4d   VALUES (DATETIM
0490: 45 28 27 6e 6f 77 27 29 2c 20 3f 2c 20 3f 29 22  E('now'), ?, ?)"
04a0: 2c 20 5b 24 5f 53 45 52 56 45 52 5b 22 52 45 4d  , [$_SERVER["REM
04b0: 4f 54 45 5f 41 44 44 52 22 5d 2c 20 24 6a 73 6f  OTE_ADDR"], $jso
04c0: 6e 5d 29 3b 0a 20 20 20 20 68 65 61 64 65 72 28  n]);.    header(
04d0: 22 4c 6f 63 61 74 69 6f 6e 3a 20 2f 65 78 74 2f  "Location: /ext/
04e0: 73 75 72 76 65 79 5f 73 75 6d 2f 24 74 62 6c 23  survey_sum/$tbl#
04f0: 74 68 61 6e 6b 73 22 29 3b 0a 7d 0a 0a 23 2d 2d  thanks");.}..#--
0500: 20 72 75 6e 0a 69 66 20 28 21 70 72 65 67 5f 6d   run.if (!preg_m
0510: 61 74 63 68 28 52 58 5f 54 42 4c 2c 20 24 74 62  atch(RX_TBL, $tb
0520: 6c 20 3d 20 62 61 73 65 6e 61 6d 65 28 24 5f 53  l = basename($_S
0530: 45 52 56 45 52 5b 22 50 41 54 48 5f 49 4e 46 4f  ERVER["PATH_INFO
0540: 22 5d 29 29 29 20 7b 0a 20 20 20 20 64 69 65 28  "]))) {.    die(
0550: 22 4e 6f 20 74 61 62 6c 65 20 6e 61 6d 65 20 67  "No table name g
0560: 69 76 65 6e 20 2f 73 75 72 76 65 79 2f 4e 41 4d  iven /survey/NAM
0570: 45 22 29 3b 0a 7d 0a 65 6c 73 65 69 66 20 28 63  E");.}.elseif (c
0580: 6f 75 6e 74 28 24 5f 50 4f 53 54 29 29 20 7b 0a  ount($_POST)) {.
0590: 20 20 20 20 23 65 72 72 6f 72 5f 72 65 70 6f 72      #error_repor
05a0: 74 69 6e 67 28 45 5f 41 4c 4c 29 3b 69 6e 69 5f  ting(E_ALL);ini_
05b0: 73 65 74 28 22 64 69 73 70 6c 61 79 5f 65 72 72  set("display_err
05c0: 6f 72 73 22 2c 20 31 29 3b 0a 20 20 20 20 73 74  ors", 1);.    st
05d0: 6f 72 65 28 24 74 62 6c 29 3b 0a 7d 0a 65 6c 73  ore($tbl);.}.els
05e0: 65 20 7b 0a 20 20 20 20 64 69 65 28 22 45 6d 70  e {.    die("Emp
05f0: 74 79 20 66 6f 72 6d 22 29 3b 0a 7d 0a 0a        ty form");.}..