added dhv.php
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Wed, 19 Oct 2011 22:39:30 +0200
changeset 36 221663a01729
parent 35 c2ac2609bd56
child 37 5bb06da69cb4
added dhv.php
.htaccess
db.schema
dhv.php
--- a/.htaccess	Fri Oct 07 11:11:45 2011 +0200
+++ b/.htaccess	Wed Oct 19 22:39:30 2011 +0200
@@ -1,2 +1,4 @@
 Options +ExecCGI
 AddHandler cgi-script .cgi
+php_flag display_errors on
+php_value error_reporting -1
--- a/db.schema	Fri Oct 07 11:11:45 2011 +0200
+++ b/db.schema	Wed Oct 19 22:39:30 2011 +0200
@@ -1,8 +1,7 @@
-DROP TABLE IF EXISTS db;
 CREATE TABLE db (
     id INTEGER PRIMARY KEY, 
     givenname TEXT, surname TEXT, email TEXT, tel TEXT,
     uuid TEXT UNIQUE, 
     created INT,
     confirmed INT DEFAULT NULL,
-    payed INT DEFAULT NULL);
+    payed INT DEFAULT NULL, pass INTEGER, rueck BOOL);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dhv.php	Wed Oct 19 22:39:30 2011 +0200
@@ -0,0 +1,213 @@
+<?
+    // image create is done on the fly
+    if (isset($_REQUEST["png"])) {
+	list($donate, $refund, $nn) = explode(":", trim($_REQUEST["png"]));
+	$sum = $donate + $refund + $nn;
+
+	$donate = $donate/$sum;
+	$refund = $refund/$sum;
+	$nn = $nn/$sum;
+
+	// dimensions
+	$width = 300;
+	$height = $width / 3;
+
+	$pie_width = $height * 0.9;
+	$pie_height = $pie_width;
+
+	$pie_x = $height / 2;
+	$pie_y = $pie_x;
+	$text_x = $pie_width * 1.2;
+
+	// Image and colors
+	$im = imagecreatetruecolor($width, $height);
+	$c_donate = imagecolorallocate($im, 255, 0, 0);
+	$c_refund = imagecolorallocate($im, 0, 225, 0);
+	$c_nn = imagecolorallocate($im, 150, 150, 150);
+	$bg = imagecolorallocate($im, 255, 255, 255);
+
+	// background
+	imagefill($im, 0, 0, $bg);
+	imagecolortransparent($im, $bg);
+	$a = 0.0;
+	if ($donate > 0) imagefilledarc($im, 
+		$pie_x, $pie_y, $pie_width, $pie_height, 
+		$a, $a += $donate*360, $c_donate, IMG_ARC_PIE);
+	if ($refund > 0) imagefilledarc($im, 
+		$pie_x, $pie_y, $pie_width, $pie_height, 
+		$a, $a += $refund*360, $c_refund, IMG_ARC_PIE);
+	if ($nn > 0) imagefilledarc($im, 
+		$pie_x, $pie_y, $pie_width, $pie_height, 
+		$a, $a += $nn*360, $c_nn, IMG_ARC_PIE);
+
+	imagestring($im, 5, $text_x, 0 + 0.1*$height, sprintf("Elbtalflieger %.1f%%", $donate*100), $c_donate);
+	imagestring($im, 5, $text_x, 1*$height/3 + 0.1*$height, sprintf("Erstattung %.1f%%", $refund*100), $c_refund);
+	imagestring($im, 5, $text_x, 2*$height/3 + 0.1*$height, sprintf("keine Angabe %.1f%%", $nn*100), $c_nn);
+
+
+	header("Content-Type: image/png");
+	imagepng($im);
+	exit;
+    }
+
+    // Template vars
+    $T = array("verified" => false,
+	       "givenname" => null,
+	       "surname" => null,
+	       "dhv" => null,
+	       "stats" => array("donate" => 0,
+			      "refund" => 0,
+			      "nn"     => 0),
+	       "email" => null,
+	       "pass" => null,
+    );
+
+    if (isset($_REQUEST["email"])) {
+	$dbh = new PDO("sqlite:var/db.sqlite3", "", "");
+
+	// sanitze the request variables
+	foreach ($_REQUEST as &$v) $v = trim($v);
+
+	// check access and state of current user
+	$sth = $dbh->prepare("SELECT givenname, surname, dhv FROM db WHERE email = :email AND pass = :pass");
+	$sth->execute(array("email" => $_REQUEST["email"], "pass" => $_REQUEST["pass"]));
+
+	$T["email"] = htmlspecialchars($_REQUEST["email"]);
+	$T["pass"] = htmlspecialchars($_REQUEST["pass"]);
+
+	if ($o = $sth->fetchObject()) {
+	    $T["verified"] = true;
+	    foreach (array("givenname", "surname", "dhv") as $k) $T[$k] = $o->{$k};
+
+	    if (isset($_REQUEST['dhv'])) {
+		$sth = $dbh->prepare("UPDATE db SET dhv = ? WHERE email = ?");
+		switch ($_REQUEST['dhv']) {
+		    case "donate": $T['dhv'] = "donate"; $v = 0; break;
+		    case "refund": $T['dhv'] = "refund"; $v = 1; break;
+		    default: $v = NULL;
+		}
+		if (isset($v)) $sth->execute(array($v, $T['email']));
+	    } else {
+		switch($T['dhv']) {
+		    case NULL: break;
+		    case 0: $T['dhv'] = "donate"; break;
+		    case 1: $T['dhv'] = "refund"; break;
+		}
+	    }
+
+	    // check overall stats
+	    $sth = $dbh->query("SELECT dhv FROM db");
+	    while ($o = $sth->fetchObject()) {
+		switch($o->{"dhv"}) {
+		    case NULL: $T["stats"]["nn"]++; break;
+		    case 0: $T["stats"]["donate"]++; break;
+		    case 1: $T["stats"]["refund"]++; break;
+		}
+	    }
+	}
+    }
+
+    //if (isset($T)) { print "<pre>\n"; var_dump($T); print "</pre>"; }
+
+
+?>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html;charset=UTF8" />
+<style type="text/css">
+<!--
+    form * label { display:block; float:left; width:12ex; }
+-->
+</style>
+</head>
+<body>
+
+[<a href='<?=$_SERVER["PHP_SELF"]?>'>HOME</a>]
+
+<h1>Retterpackkurs 15.10.2011</h1>
+
+<p>
+Wie ihr wißt, zahlt der DHV für jedes Mitglied an den ausrichtenden
+Verein einen Zuschuß von etwas über 11€.  Die Frage ist jetzt, was
+machen wir mit diesem Zuschuß.
+
+<? if (!$T['verified']) { ?>
+<p>
+
+    <? if (isset($_REQUEST["email"])) { ?>
+	<font color=red>Deine Angaben sind so leider nicht richtig. Bitte
+	prüfe sie noch mal, oder kontaktiere 
+	<a href="mailto:hs+retter@schlittermann.de">hs+retter@schlittermann.de</a>
+	</font>
+    <? } else { ?>
+	Bitte verwende Deine Mailadresse und den Code aus der Mail, die Du
+	erhalten hast, um Deinen Wunsch entsprechend einzutragen.
+    <? } ?>
+
+<p>
+<form>
+<p>
+    <label for=email>Mail-Adresse:</label>
+    <input id=email name=email type=text value="<?=$T["email"]?>"/><br>
+    <label for=pass>Code:</label>
+    <input id=pass name=pass type=text value="<?=$T["pass"]?>"/></br>
+    <input type=submit value=OK name=_ok />
+</form>
+
+<? } else { ?>
+
+<p>
+Bitte Deine Entscheidung (Du kannst sie bis einschließlich 31. Oktober
+2011 jederzeit ändern):</br>
+<form>
+    <input id=dhv_donate type=radio name=dhv value="donate"
+	<?=$T['dhv']=="donate"?"checked":""?> onChange='submit()'/>
+    <label for=dhv_donate>
+	Die Elbtalflieger erhalten diese 11€ als Spende. Und Du drei
+	Windenschlepps für umsonst.
+	</label></br>
+
+    <input id=dhv_refund type=radio name=dhv value="refund" 
+	<?=$T['dhv']=="refund"?"checked":""?> onChange='submit()'/>
+    <label for=dhv_refund>
+	Ich möchte das Geld erstattet haben.
+	</label></br>
+
+    <input type=hidden name=email value='<?=$T['email']?>'/>
+    <input type=hidden name=pass  value='<?=$T['pass']?>'/>
+
+    <!-- <input type=submit value="OK"/> -->
+</form>
+
+<p>
+Zu Deiner Orientierung haben wir hier die aktuelle Entscheidungsquote
+dargestellt:
+
+<p>
+    <img src='<?=$_SERVER["PHP_SELF"]?>?png=<?=implode(":", $T["stats"])?>' width=20% float=right/>
+
+<? } ?>
+
+<? if($T['dhv'] == 'refund') { ?>
+
+    <p>
+    Für die Erstattung des Geldes nimm bitte Kontakt mit 
+    <a href="mailto:hs+retter@schlittermann.de">Heiko Schlittermann</a>
+    auf, wir benötigen die Bankverbindung, auf die wir den Betrag
+    überweisen sollen.
+
+<? } else if ($T['dhv'] == 'donate') { ?>
+
+    <p>
+    Die <a href="http://www.elbtalflieger.de/">Elbtalflieger</a> sind Dir für diese Spende so dankbar, daß sie Dich 
+    zu drei kostenlosen Windenschlepps und einem anschließenden
+    Landebier einladen.
+
+<? } ?>
+
+
+<hr/>
+<div align=right>
+Scripting <a href="http://schlittermann.de">Heiko Schlittermann</a>
+</body>
+</html>