survey/umfrage.php

185 lines
6.1 KiB
PHP

<?php
use ArangoDBClient\CollectionHandler;
use ArangoDBClient\Connection;
use ArangoDBClient\ConnectionOptions;
use ArangoDBClient\DocumentHandler;
use ArangoDBClient\Statement;
use ArangoDBClient\UpdatePolicy;
require "vendor/autoload.php";
require "Seite.php";
include "config.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);
if (!isset($_SESSION['name'])){
$statement = new Statement($connection, [
'query' => 'for question in questions filter question.type=="aux" return question',
'count' => true,
'batchSize' => 1000,
'bindVars' => null,
'sanitize' => true,
]
);
$cursor = $statement->execute();
$questions = array();
foreach ($cursor->getAll() as $doc) {
$questions[] = json_decode(json_encode($doc));
}
$seite = new \goeranh\Seite("Abiturumfrage");
$inhalt = '
<form action="answers.php" method="post">
<table>
';
foreach ($questions as $question){
$inhalt .= '<tr><td><label for="'.$question->_key.'">'.$question->question.'</label></td>
<td><input type="text" name="'.$question->_key.'" placeholder="'.$question->question.'"></td></tr>';
}
$inhalt .= '
<tr><td></td><td><button onerror="submit" style="width: 100%">Weiter</button></td></tr>
</table>
</form>
';
$seite->addInhalt($inhalt);
$seite->augeben();
}elseif(!isset($_SESSION['personal'])){
$statement = new Statement($connection, [
'query' => 'for question in questions filter question.type=="personal" return question',
'count' => true,
'batchSize' => 1000,
'bindVars' => null,
'sanitize' => true,
]
);
$cursor = $statement->execute();
$questions = array();
foreach ($cursor->getAll() as $doc) {
$questions[] = json_decode(json_encode($doc));
}
$seite = new \goeranh\Seite("Abiturumfrage");
$inhalt = '
<form action="answers.php" method="post">
<table>
';
foreach ($questions as $question){
$inhalt .= '<tr><td><label for="'.$question->_key.'">'.$question->question.'</label></td>
<td width="100%"><input type="text" name="'.$question->_key.'" placeholder="'.$question->question.'"></td></tr>';
}
$inhalt .= '
<tr><td></td><td><button onerror="submit" style="width: 100%">Weiter</button></td></tr>
</table>
</form>
';
$seite->addInhalt($inhalt);
$seite->augeben();
}elseif(!isset($_SESSION['schueler'])){
$statement = new Statement($connection, [
'query' => 'for question in questions filter question.type=="schülerawards" return question',
'count' => true,
'batchSize' => 1000,
'bindVars' => null,
'sanitize' => true,
]
);
$cursor = $statement->execute();
$questions = array();
foreach ($cursor->getAll() as $doc) {
$questions[] = json_decode(json_encode($doc));
}
$seite = new \goeranh\Seite("Abiturumfrage");
$inhalt = '
<form action="answers.php" method="post">
<table>
';
foreach ($questions as $question){
$inhalt .= '<tr><td><label for="'.$question->_key.'">'.$question->question.'</label></td>
<td width="100%"><input type="text" name="'.$question->_key.'" placeholder="'.$question->question.'"></td></tr>';
}
$inhalt .= '
<tr><td></td><td><button onerror="submit" style="width: 100%">Weiter</button></td></tr>
</table>
</form>
';
$seite->addInhalt($inhalt);
$seite->augeben();
}elseif(!isset($_SESSION['lehrer'])){
$statement = new Statement($connection, [
'query' => 'for question in questions filter question.type=="lehrerawards" return question',
'count' => true,
'batchSize' => 1000,
'bindVars' => null,
'sanitize' => true,
]
);
$cursor = $statement->execute();
$questions = array();
foreach ($cursor->getAll() as $doc) {
$questions[] = json_decode(json_encode($doc));
}
$seite = new \goeranh\Seite("Abiturumfrage");
$inhalt = '
<form action="answers.php" method="post">
<table>
';
foreach ($questions as $question){
$inhalt .= '<tr><td><label for="'.$question->_key.'">'.$question->question.'</label></td>
<td width="100%"><input type="text" name="'.$question->_key.'" placeholder="'.$question->question.'"></td></tr>';
}
$inhalt .= '
<tr><td></td><td><button onerror="submit" style="width: 100%">Weiter</button></td></tr>
</table>
</form>
';
$seite->addInhalt($inhalt);
$seite->augeben();
}else{
$seite = new \goeranh\Seite('Danke fürs Mitmachen!');
$inhalt = '<h1>Danke, dass deine Daten angegeben hast.</h1>';
$seite->addInhalt($inhalt);
$seite->augeben();
}