Collection of themes/skins for the Fossil SCM

⌈⌋ ⎇ branch:  Fossil Skins Extra


Artifact [9463ed8860]

Artifact 9463ed8860d06399be4e0642ad56c61a6f6c19b5:

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

#!/usr/bin/php-cgi -dcgi.force_redirect=0
<?php
# encoding: utf-8
# api: cgi
# type: display
# category: database
# title: Survey summarize
# description: Only collects
# version: 0.2
# state: alpha
# config: -
#
# Requires a link like  "/ext/survey_sum/SAMPLE",
# and counts the numeric fields (checkboxes yes/no).
# It's just meant for a quick result list, and
# outputs approximate points 🞓


#-- 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 show($tbl) {
    $r = [];
    foreach (db("SELECT fields FROM `survey_$tbl`") as $j) {
        if ($j = json_decode($j["fields"])) {
            foreach ($j as $k=>$v) {
                if (is_numeric($v)) {
                     @$r[$k] += $v;
                }
            }
        }
    }
ini_set("display_errors", 1);
    if ($r) {
         print("| question | score |\n|-------|-------|\n");
         $max = max($r) + 1;
         foreach ($r as $k=>$v) {
             $k = htmlspecialchars($k, ENT_QUOTES); # though already MD
             $n = ($v / $max) * 20.1;
             $n = str_repeat("🞓", (int)$n);
             print("| $k | $n |\n");
         }
    }
}

#-- run
if ($tbl = preg_replace("/\W+/", "", basename($_SERVER["PATH_INFO"]))) {
    header("Content-Type: text/x-markdown");
    print("\n##### survey $tbl\n##### Survey '*$tbl*' (approx. results)\n\n");
    show($tbl);
}
else {
    die("No table name given /survey/NAME");
}