survey/answers.php

93 lines
3.5 KiB
PHP

<?php
use ArangoDBClient\CollectionHandler;
use ArangoDBClient\Connection;
use ArangoDBClient\ConnectionOptions;
use ArangoDBClient\Document;
use ArangoDBClient\DocumentHandler;
use ArangoDBClient\UpdatePolicy;
require 'config.php';
require "vendor/autoload.php";
require "Seite.php";
session_start();
$connectionOptions = array(
// server endpoint to connect to
//ConnectionOptions::OPTION_ENDPOINT => 'tcp://10.16.17.154:8529',
ConnectionOptions::OPTION_ENDPOINT => 'tcp://' . $server . ':8529',
// authorization type to use (currently supported: 'Basic')
ConnectionOptions::OPTION_AUTH_TYPE => 'Basic',
// user for basic authorization
ConnectionOptions::OPTION_AUTH_USER => $dbuser,
// password for basic authorization
ConnectionOptions::OPTION_AUTH_PASSWD => $passwd,
// connection persistence on server. can use either 'Close' (one-time connections) or 'Keep-Alive' (re-used connections)
ConnectionOptions::OPTION_CONNECTION => 'Close',
// connect timeout in seconds
ConnectionOptions::OPTION_TIMEOUT => 3,
// whether or not to reconnect when a keep-alive connection has timed out on server
ConnectionOptions::OPTION_RECONNECT => true,
// optionally create new collections when inserting documents
ConnectionOptions::OPTION_CREATE => true,
// optionally create new collections when inserting documents
ConnectionOptions::OPTION_UPDATE_POLICY => UpdatePolicy::LAST,
ConnectionOptions::OPTION_DATABASE => $database,
);
// open connection
$connection = new Connection($connectionOptions);
$collectionHandler = new CollectionHandler($connection);
$documentHandler = new DocumentHandler($connection);
$edgeHandler = new \ArangoDBClient\EdgeHandler($connection);
if (!isset($_SESSION['name'])) {
if (count($_POST) == 2) {
$user = $documentHandler->insert($collectionHandler->get('users'), new Document());
foreach (array_keys($_POST) as $key) {
var_dump($keys);
$edge = new Document();
$edge->set("answer", $_POST[$key]);
$edge->set('_from', $user);
$edge->set('_to', 'questions/' . $key);
$documentHandler->insert('answered', $edge);
}
$_SESSION['name'] = $user;
}
} elseif (!isset($_SESSION['personal'])) {
foreach (array_keys($_POST) as $key) {
if ($_POST[$key] != '') {
$edge = new Document();
$edge->set("answer", $_POST[$key]);
$edge->set('_from', $_SESSION['name']);
$edge->set('_to', 'questions/' . $key);
$documentHandler->insert('answered', $edge);
}
}
$_SESSION['personal'] = true;
} elseif (!isset($_SESSION['schueler'])) {
foreach (array_keys($_POST) as $key) {
if ($_POST[$key] != '') {
$edge = new Document();
$edge->set("answer", $_POST[$key]);
$edge->set('_from', $_SESSION['name']);
$edge->set('_to', 'questions/' . $key);
$documentHandler->insert('answered', $edge);
}
}
$_SESSION['schueler'] = true;
} elseif (!isset($_SESSION['lehrer'])) {
foreach (array_keys($_POST) as $key) {
if ($_POST[$key] != '') {
$edge = new Document();
$edge->set("answer", $_POST[$key]);
$edge->set('_from', $_SESSION['name']);
$edge->set('_to', 'questions/' . $key);
$documentHandler->insert('answered', $edge);
}
}
$_SESSION['lehrer'] = true;
}
header('Location: umfrage.php');