summaryrefslogtreecommitdiff
path: root/www/vote.php
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-26 21:55:43 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-26 21:55:43 +0000
commitaf157c6bb72518f8ee3096f6370c920ef9b965a3 (patch)
tree74c2ef2e92825ac5b8bae214fb93680774733724 /www/vote.php
parent44fd0e29f4d856058f3bac3a3581d00919420169 (diff)
downloadsemanticscuttle-af157c6bb72518f8ee3096f6370c920ef9b965a3.tar.gz
semanticscuttle-af157c6bb72518f8ee3096f6370c920ef9b965a3.tar.bz2
basic voting system works; but layout is missing
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@432 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'www/vote.php')
-rw-r--r--www/vote.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/www/vote.php b/www/vote.php
new file mode 100644
index 0000000..91f5c34
--- /dev/null
+++ b/www/vote.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * We do expect three parameters:
+ * - type (for/against)
+ * - bookmark id
+ * - url we shall redirect to (?from=)
+ *
+ * vote/for/123?from=xyz
+ */
+require_once '../src/SemanticScuttle/header.php';
+
+if (!$GLOBALS['enableVoting']) {
+ header('HTTP/1.0 501 Not implemented');
+ echo 'voting is disabled';
+ exit(1);
+}
+
+
+$us = SemanticScuttle_Service_Factory::get('User');
+$vs = SemanticScuttle_Service_Factory::get('Vote');
+
+if (!$us->isLoggedOn()) {
+ header('HTTP/1.0 400 Bad Request');
+ echo 'need a logged on user';
+ exit(1);
+}
+$user = $us->getCurrentUser();
+$user = $user['uId'];
+
+if (!isset($_SERVER['PATH_INFO'])) {
+ //we got a problem
+ header('HTTP/1.0 500 Internal Server Error');
+ echo 'PATH_INFO not found';
+ exit(2);
+}
+
+//we should really use net_url_mapper here
+list($url, $type, $bookmark) = explode('/', $_SERVER['PATH_INFO']);
+
+if ($type != 'for' && $type != 'against') {
+ header('HTTP/1.0 400 Bad Request');
+ echo 'type has to be "for" or "against"';
+ exit(3);
+}
+if (!is_numeric($bookmark)) {
+ header('HTTP/1.0 400 Bad Request');
+ echo 'Bookmark must be numeric';
+ exit(4);
+}
+$bookmark = (int)$bookmark;
+
+if (!isset($_GET['from']) || $_GET['from'] == '') {
+ header('HTTP/1.0 400 Bad Request');
+ echo 'Missing "from" parameter';
+ exit(5);
+}
+$from = $_GET['from'];
+
+
+if ($vs->hasVoted($bookmark, $user)) {
+ //already voted
+ header('HTTP/1.0 412 Precondition failed');
+ echo 'Bookmark has been already voted for';
+ exit(6);
+}
+
+$vs->vote($bookmark, $user, $type == 'for' ? 1 : -1);
+header('Location: ' . $from);
+?> \ No newline at end of file