aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/functions.php
diff options
context:
space:
mode:
authorroot2014-09-25 10:26:56 +0200
committerroot2014-09-25 10:26:56 +0200
commit2036626b560f22efd59673187a2de3b1319fcf8a (patch)
tree5180be078e3758b6fe3c37834cf6074c148394d1 /bootstrap/functions.php
parent7ea240aef9b75758d05cb5212ef7c99b47b4180b (diff)
downloadjungegemeinde-2036626b560f22efd59673187a2de3b1319fcf8a.tar.gz
version 4.0
Diffstat (limited to 'bootstrap/functions.php')
-rw-r--r--bootstrap/functions.php382
1 files changed, 361 insertions, 21 deletions
diff --git a/bootstrap/functions.php b/bootstrap/functions.php
index 60408a2..3e937d2 100644
--- a/bootstrap/functions.php
+++ b/bootstrap/functions.php
@@ -1,5 +1,18 @@
<?php
+function lredirect($goto){
+ global $user;
+ if ( $user->isLoggedIn() != 1){
+ redirect("login&goto=".$goto);
+ }
+}
+
+function redirect($goto){
+ header($_SERVER["SERVER_PROTOCOL"] . " 302 Moved");
+ header("Location: /?page=".$goto);
+ ob_clean();
+ exit;
+}
function failure($reason, $httpcode, $ajax = true, $heading = NULL){
# send header with $httpcode
@@ -23,31 +36,56 @@ function failure($reason, $httpcode, $ajax = true, $heading = NULL){
exit;
}
-function print_login(){
+function print_login($option = false){
if(isset($_GET["goto"]) && $_GET["goto"] != "")
- $goto = $_GET["goto"];
+ $goto = htmlentities($_GET["goto"]);
else
$goto = "index";
+
+ global $user;
+ if ( $user->isLoggedIn() ){
+ redirect("index");
+ }
?>
<form class="form-horizontal" method="POST" action="/?page=action&task=login&goto=<?php echo $goto; ?>">
<fieldset>
<!-- Form Name -->
-<legend><h1>Junge Gemeinde Adlershof</h1><p>Login required</p></legend>
+<legend><h1>Junge Gemeinde Adlershof</h1>
+<?php
+ if ( ! $option ){
+?>
+<p>Login required</p>
+<?php
+ } else if ( $option == "logout" ){
+?>
+<p style="color:red">Logout erfolgreich!</p>
+<?php
+ } else if ( $option == "password" ) {
+?>
+<p style="color:red">Nutzer/Passwort falsch</p>
+<?php
+ } else if ( $option == "missing") {
+?>
+<p style="color:red">Bitte fülle alle Felder aus!</p>
+<?php
+ }
+?>
+</legend>
<!-- Text input-->
<div class="form-group">
- <label class="col-md-4 control-label" for="name">Username*:</label>
- <div class="col-md-5">
- <input id="name" name="name" placeholder="Put your username here." class="form-control input-md" required="" type="text">
+ <label class="col-md-4 control-label" for="name">Username*</label>
+ <div class="col-md-4">
+ <input id="name" name="name" placeholder="Name (Pflicht)" class="form-control input-md" required="" type="text">
</div>
</div>
<!-- Password input-->
<div class="form-group">
- <label class="col-md-4 control-label" for="password">Password*:</label>
- <div class="col-md-5">
- <input id="password" name="password" placeholder="Put your password here." class="form-control input-md" required="" type="password">
+ <label class="col-md-4 control-label" for="password">Password*</label>
+ <div class="col-md-4">
+ <input id="password" name="password" placeholder="Passwort (Pflicht)" class="form-control input-md" required="" type="password">
</div>
</div>
@@ -61,28 +99,60 @@ else
</fieldset>
</form>
+<br>
+<p><strong>Mit * markierte Felder sind Pflichtfelder.</strong></p>
+</div>
+<div class="row">
+<a href="/?page=recover" title="Recover your password">[Passwort vergessen?]</a>
</div>
<?php
}
+function print_logout(){
+ global $user;
+ $user->logout();
+ print_login("logout");
+}
+
function print_index(){
?>
<h1>Junge Gemeinde Adlershof</h1>
+ <br>
</div>
<div class="row">
+ <img src="/static/kitten-prays-small.jpg" alt="praing kitten" class="img-responsive">
+ </div>
+ <br>
+ <div class="row">
+ <p>Wir sind die Junge Gemeinde in Adlershof.</p>
+ <p>Wir treffen uns immer Donnerstags um 19:30 Uhr in der Remise Arndtstraße 12a.</p>
+ <p>Am besten sind wir über unsere <span id="mail"><strong>Aktiviere JavaScript um die E-Mail Adresse zu sehen!</strong></span> erreichbar.</p>
</div>
<?php
}
-function print_list(){
+function print_list($option = false){
+ lredirect("liste");
global $db;
$result = $db->doQuery("SELECT * FROM " . DBPREFIX . "member;");
?>
<h1>Adress Liste</h1>
+<?php
+ if ( $option == "update"){
+?>
+<h4 style="color:red;">Es existiert kein Mitglied mit dieser ID</h4>
+ <br>
+<?php
+ } else if ( $option == false ) {
+?>
<br>
+<?php
+ }
+?>
</div>
<div class="row">
+ <div class="table-responsive">
<table width='60%' class='table table-striped'>
<thead>
<tr>
@@ -109,17 +179,13 @@ function print_list(){
<td>".htmlentities($row['email'])."</td>
<td>".htmlentities($row['geburtstag'])."</td>
<td><a href='/?page=update&id=".htmlentities($row['member_id'])."'><input type='checkbox' name='change' value='true'></a></td>
- <tr>";
+ </tr>";
$count++;
}
?>
- <?php /*
- <tr><td align='center'><a href=\"/liste/".$row[0]."\">".$count."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[1]."</a></td><td align='left'>
- <a href=\"/liste/".$row[0]."\">".$row[2]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[3]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[4]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[5]."</a></td><td align='left'><a href=\"/liste/".$row[0]."\">".$row[6]."</a></td><td align='center'><a href=\"/liste/".$row[0]."\"><input type='checkbox' name='change' value='true'</td></a><tr>
- */
- ?>
</tbody>
</table>
+ </div>
<form method="POST" action="/?page=add">
<button id="singlebutton" class="btn btn-info" type="submit">Füge jemanden hinzu</button>
</form>
@@ -130,20 +196,22 @@ function print_list(){
}
function print_update_list($id){
+ lredirect("liste");
global $db;
$sql = $db->prepare("SELECT * FROM " . DBPREFIX . "member WHERE member_id = %d", $id);
$result = $db->doQuery($sql);
if(!$result){
- echo "Fail!";
+ print_list("update");
exit;
}
- while ( $row = $result->fetch_array(MYSQLI_ASSOC) ){
+ if ( $row = $result->fetch_array(MYSQLI_ASSOC) ){
?>
<h1>Änderung für <?php echo htmlentities($row['name']); ?></h1>
</div>
<div class="row">
- <form method='POST' action='/?page=action&task=update&id=<?php echo htmlentities($row['memberid']); ?>&goto=liste'>
+ <form method='POST' action='/?page=action&task=update&id=<?php echo htmlentities($row['member_id']); ?>&goto=liste'>
+ <div class="table-responsive">
<table class='table'>
<thead>
<tr>
@@ -173,19 +241,24 @@ function print_update_list($id){
</tr>
</tbody>
</table>
+ </div>
<button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Ändere!</button>
</form>
</div>
<?php
+ } else {
+ print_list("update");
}
}
function print_add_entry_to_list(){
+ lredirect("liste");
?>
<h1>Füge die Daten hinzu</h1>
</div>
<div class="row">
- <form method='POST' action='/?page=action&task=add&goto=liste'>
+ <form method='POST' action='/?page=action&task=add&goto=liste&_flush=<?php echo $c->token; ?>'>
+ <div class="table-responsive">
<table class='table'>
<thead>
<tr>
@@ -215,6 +288,7 @@ function print_add_entry_to_list(){
</tr>
</tbody>
</table>
+ </div>
<button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Hinzufügen!</button>
</form>
</div>
@@ -222,6 +296,7 @@ function print_add_entry_to_list(){
}
function _add_entry(){
+ lredirect("liste");
global $db;
$sql = $db->prepare("INSERT INTO " . DPREFIX . "member (id, name, adresse, telefonnummer, handynummer, email, geburtstag) VALUES (NULL. %s, %s, %s, %s, %s, %s);", $_POST['name'], $_POST['adresse'], $_POST['telefonnummer'], $_POST['handynummer'], $_POST['email'], $_POST['geburtstag']);
@@ -232,7 +307,272 @@ function _add_entry(){
}
function print_404(){
- header($_SERVER['HTTP_PROTOCOL'] . ' 404 Not Found');
+ header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
+?>
+<h1>404 - Not Found</h1>
+<br>
+<h4>The requested page (<?php echo htmlentities($_SERVER['REQUEST_URI']); ?>) wasn't found on this server.</h4>
+</div>
+<?php
+}
+
+function print_register($option = false){
+ global $user;
+ if ( $user->isLoggedIn() ){
+ redirect("index");
+ }
+?>
+
+<form class="form-horizontal" method='POST' action='/?page=action&task=register&goto=account'>
+<fieldset>
+
+<!-- Form Name -->
+<legend><h1>Junge Gemeinde Adlershof</h1>
+<?php
+ if ( $option == false ){
+?>
+<p>Register</p>
+<?php
+ } else if ( $option == "password") {
+?>
+<p style="color:red;">Passwörter stimmen nicht überein!</p>
+<?php
+ } else if ( $option == "missing") {
+?>
+<p style="color:red;">Bitte fülle alle mit '*' markierten Felder aus!</p>
+<?php
+ } else if ( $option == "key") {
+?>
+<p style="color:red;">Registrierung verweigert!</p>
+<?php
+ } else if ( $option == "double") {
?>
+<p style="color:red;">Nutzer/E-Mail gibt es schon!</p>
<?php
+ } else if ( $option == "double") {
+?>
+<p style="color:red;">Interner Fehler!</p>
+<?php
+ }
+?>
+</legend>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="name">Name*</label>
+ <div class="col-md-4">
+ <input id="name" name="name" placeholder="Name (Pflicht)" class="form-control input-md" required="" type="text">
+
+ </div>
+</div>
+
+<!-- Password input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="password">Passwort*</label>
+ <div class="col-md-4">
+ <input id="password" name="password" placeholder="Passwort (Pflicht)" class="form-control input-md" required="" type="password">
+
+ </div>
+</div>
+
+<!-- Password input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="confirm">Bestätige Passwort*</label>
+ <div class="col-md-4">
+ <input id="confirm" name="confirm" placeholder="Passwort (Pflicht)" class="form-control input-md" required="" type="password">
+
+ </div>
+</div>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="email">E-Mail</label>
+ <div class="col-md-4">
+ <input id="email" name="email" placeholder="E-Mail" class="form-control input-md" type="text">
+ <span class="help-block">Deine E-Mail wird gebraucht, wenn du dein Passwort vergessen hast.</span>
+ </div>
+</div>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="key">Key*</label>
+ <div class="col-md-4">
+ <input id="key" name="key" placeholder="Schlüssel (Pflicht)" class="form-control input-md" required="" type="text">
+ <span class="help-block">Du solltest den Schlüssel in einer Mail bekommen haben.</span>
+ </div>
+</div>
+
+<!-- Button -->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button id="submit" name="submit" class="btn btn-info">Registrieren</button>
+ </div>
+</div>
+
+</fieldset>
+</form>
+<br>
+<p><strong>Mit * markierte Felder sind Pflichtfelder.</strong></p>
+</div>
+<?php
+}
+
+function print_account($option = false){
+ lredirect("accout");
+ global $user;
+?>
+<form class="form-horizontal" method="POST" action="/?page=action&task=account&goto=account">
+<fieldset>
+
+<!-- Form Name -->
+<legend>
+<h1><?php echo htmlentities($_SESSION["username"]);?></h1>
+<?php
+ if ( $option == false && ! isset($_GET["success"]) && $_GET["success"] != 1){
+?>
+<p>Ändere deine Daten</p>
+<?php
+ } else if ( $option == "info" ){
+?>
+<p style="color:red;">Bitte fülle alle notwendigen Felder aus!</p>
+<?php
+ } else if ( $option == "password" ){
+?>
+<p style="color:red;">Dein Passwort stimmt nicht!</p>
+<?php
+ } else if ( $option == "double" ){
+?>
+<p style="color:red;">Nutzer/E-Mail schon vergeben!</p>
+<?php
+ } else if ( $option == "database" ){
+?>
+<p style="color:red;">Interner Fehler!</p>
+<?php
+ } else if ( $option == "success" || $_GET["success"] == 1 ){
+?>
+<p style="color:green;">Erfolgreich aktualisiert!</p>
+<?php
+ }
+?>
+</legend>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="name">Name*</label>
+ <div class="col-md-4">
+ <input id="name" name="name" placeholder="Neuer Name" class="form-control input-md" type="text" value="<?php echo $_SESSION["username"];?>" required="">
+ <span class="help-block">Wechsle deinen Namen hier.</span>
+ </div>
+</div>
+
+<!-- Password input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="passwordinput">Neues Passwort</label>
+ <div class="col-md-4">
+ <input id="passwordinput" name="password" placeholder="Neues Passwort" class="form-control input-md" type="password">
+ <span class="help-block">Ändere dein Passwort. Lass das Feld leer, wenn du es nicht ändern möchtest.</span>
+ </div>
+</div>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="textinput">E-Mail</label>
+ <div class="col-md-4">
+ <input id="textinput" name="email" placeholder="E-Mail" class="form-control input-md" type="text" value="<?php echo $user->getEmail(); ?>">
+ <span class="help-block">Ändere deine E-Mail Adresse.</span>
+ </div>
+</div>
+
+<!-- Password input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="confirm">Passwort*</label>
+ <div class="col-md-4">
+ <input id="confirm" name="confirm" placeholder="Bestätige mit deinem alten Passwort." class="form-control input-md" required="" type="password">
+ <span class="help-block">Bestätige die Angaben mit deinem gültigen Passwort.</span>
+ </div>
+</div>
+
+<!-- Button -->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button id="submit" name="submit" class="btn btn-primary">Ändere!</button>
+ </div>
+</div>
+
+</fieldset>
+</form>
+<br>
+<p><strong>Mit * markierte Felder sind Pflichtfelder.</strong></p>
+ </div>
+<?php
+}
+
+function print_recover($option = false){
+?>
+<form class="form-horizontal" method='POST' action='/?page=action&task=recover'>
+<fieldset>
+
+<!-- Form Name -->
+<legend><h1>Junge Gemeinde Adlershof</h1>
+<?php
+ if(isset($_GET["track"])){
+ if ($_GET["track"] == 1) {
+?>
+<p style="color:green;">Passwort zugeschickt!</p>
+<?php
+ } else {
+?>
+<p style="color:red;">Fehler! Passwort konnte nicht geändert werden.</p>
+<?php
+ }
+ } else {
+?>
+<p>Passwort wiederherstellen</p>
+<?php
+ }
+?>
+</legend>
+
+<!-- Text input-->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="email">E-Mail*</label>
+ <div class="col-md-4">
+ <input id="email" name="email" placeholder="Deine hinterlegte E-Mail Adresse." class="form-control input-md" required="" type="text">
+ <span class="help-block">Wenn deine E-Mail gespeichert ist, wird dir das neue Passwort automatisch zugestellt.</span>
+ </div>
+</div>
+
+<!-- Button -->
+<div class="form-group">
+ <label class="col-md-4 control-label" for="submit"></label>
+ <div class="col-md-4">
+ <button id="submit" name="submit" class="btn btn-primary">Recover!</button>
+ </div>
+</div>
+
+</fieldset>
+</form>
+
+</div>
+<?php
+}
+
+function minify($buffer){
+ $search = array(
+ '/\>[^\S ]+/s', // strip whitespaces after tags, except space
+ '/[^\S ]+\</s', // strip whitespaces before tags, except space
+ '/(\s)+/s' // shorten multiple whitespace sequences
+ );
+
+ $replace = array(
+ '>',
+ '<',
+ '\\1'
+ );
+
+ $buffer = preg_replace($search, $replace, $buffer);
+
+ return $buffer;
}