diff options
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/action.php | 17 | ||||
| -rw-r--r-- | bootstrap/bootstrap.php | 25 | ||||
| -rw-r--r-- | bootstrap/class/mysql.php | 24 | ||||
| -rw-r--r-- | bootstrap/config.php | 12 | ||||
| -rw-r--r-- | bootstrap/functions.php | 214 | ||||
| -rw-r--r-- | bootstrap/index.php | 83 | ||||
| -rw-r--r-- | bootstrap/setup.php | 12 | ||||
| -rw-r--r-- | bootstrap/static/header.php | 6 | ||||
| -rw-r--r-- | bootstrap/static/style.css | 66 |
9 files changed, 377 insertions, 82 deletions
diff --git a/bootstrap/action.php b/bootstrap/action.php new file mode 100644 index 0000000..e6ce5c6 --- /dev/null +++ b/bootstrap/action.php @@ -0,0 +1,17 @@ +<?php + +if ( ! isset($_GET["page"]) || $_GET["page"] != "action" ){ + header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); + exit; +} + +if ( ! isset($_GET["task"]) || $_GET["task"] == "" ){ + header($_SERVER["SERVER_PROTOCOL"] . "400 Wrong Request"); + header("Location: /?page=index"); +} + +switch($_GET["task"]){ + case("login"): + + break; +} diff --git a/bootstrap/bootstrap.php b/bootstrap/bootstrap.php index 262113a..36c298e 100644 --- a/bootstrap/bootstrap.php +++ b/bootstrap/bootstrap.php @@ -4,11 +4,11 @@ require_once( dirname(__FILE__) . '/config.php'); # absolute path -if ( ! defined(ABSPATH) ) +if ( ! defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); # scheme, set to https if set, otherwise plain http -if ( ! defined(SCHEME) ){ +if ( ! defined('SCHEME') ){ if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') define('SCHEME', 'https://'); else @@ -16,25 +16,25 @@ if ( ! defined(SCHEME) ){ } # hostname -if ( ! defined(HOST) ) +if ( ! defined('HOST') ) define('HOST', $_SERVER['HTTP_HOST']); -if ( ! defined(DOMAIN) ) +if ( ! defined('DOMAIN') ) define('DOMAIN', SCHEME . HOST); # define session name -if ( ! defined(SESSION) ) +if ( ! defined('SESSION') ) define('SESSION', 'JGSID'); -# define include path for vfs-class files -if ( ! defined(INCLASS) ) +# define include path for class files +if ( ! defined('INCLASS') ) define('INCLASS', 'class/'); # redis access -# if ( ! defined(USE_REDIS) ) +# if ( ! defined('USE_REDIS') ) # define('USE_REDIS', false); -# if ( ! defined(REDIS_CONNECT) ) +# if ( ! defined('REDIS_CONNECT') ) # define('REDIS_CONNECT', '/var/run/redis/redis.sock'); -# if ( ! defined(REDIS_DBNAME) ) +# if ( ! defined('REDIS_DBNAME') ) # define('REDIS_DBNAME', 1); # redirects to correct host @@ -46,9 +46,8 @@ if ( $_SERVER['HTTP_HOST'] != HOST){ require(ABSPATH . 'functions.php'); require(ABSPATH . INCLASS . 'mysql.php'); -require(ABSPATH . INCLASS . 'vfsuser.php'); -require(ABSPATH . INCLASS . 'vfsdata.php'); +require(ABSPATH . INCLASS . 'user.php'); # first install only if ( file_exists(ABSPATH . 'setup.php') ) - require(ABSPATh . 'setup.php'); + require(ABSPATH . 'setup.php'); diff --git a/bootstrap/class/mysql.php b/bootstrap/class/mysql.php index 0140994..8d75538 100644 --- a/bootstrap/class/mysql.php +++ b/bootstrap/class/mysql.php @@ -15,7 +15,7 @@ class db { failure("<p>".$e->getMessage()."</p>", '500 Server Failure', false, '<h1>Failed to open database connection.</h1>'); } - if ( $this->db->connect_errno() ){ + if ( $this->db->connect_errno ){ failure("<p>Can't connect to the database. MySQL gave this error code: " . $this->db->connect_errno . "</p>", '500 Server Failure', false, '<h1>Connection to MySQL server failed.</h1>'); } @@ -46,7 +46,7 @@ class db { if ( ! $this->check() ) return false; - return $this->db->query($sql); + return $this->db->query($string); } # does multiple queries WITHOUT output (INSERT, UPDATE, DELETE... ) @@ -63,7 +63,7 @@ class db { break; if ( ! $this->db->next_result() ){ if ( $this->db->error != "" ){ - $res->free(); + //$result->free(); return false; } } @@ -117,8 +117,8 @@ class db { name VARCHAR(70), UNIQUE(name), password VARCHAR(70), UNIQUE(password), email VARCHAR(70), UNIQUE(email), - register INTEGER, - ENGINE=InnoDB;'; + register INTEGER + ) ENGINE=InnoDB;'; $banned_user_table = 'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'banned_user @@ -131,7 +131,19 @@ class db { ) ENGINE=InnoDB;'; - if ( ! $this->execMultipleQueries('BEGIN; '. $user_table . ' ' . $banned_user_table . ' END;') ) + $jg_table = + 'CREATE TABLE IF NOT EXISTS ' . DBPREFIX . 'member + ( member_id INTEGER AUTO_INCREMENT NOT NULL, PRIMARY KEY(member_id), + name varchar(70), UNIQUE(name), + adresse TEXT, + telefonnummer TEXT, + handynummer TEXT, + email varchar(70), UNIQUE(email), + geburtstag TEXT + ) + ENGINE=InnoDB;'; + + if ( ! $this->execMultipleQueries('BEGIN; '. $user_table . ' ' . $banned_user_table . ' ' . $jg_table . ' COMMIT;') ) failure("<p>There was a problem during bootstrapping the database schema. " . $this->db->error . "</p>", '500 Server Failure', false, "<h1>CREATE TABLE FAILED</h1>"); } diff --git a/bootstrap/config.php b/bootstrap/config.php index 5c66d07..e39fb57 100644 --- a/bootstrap/config.php +++ b/bootstrap/config.php @@ -1,12 +1,12 @@ <?php ### mysql access -define('DBHOST', 'localhost'); -define('DBUSER', 'vfs-user'); -define('DBNAME', 'vfs'); +define('DBHOST', '127.0.0.1'); +define('DBUSER', 'jg'); +define('DBNAME', 'jg'); define('DBPASSWORD', 'secretpassword'); define('DBCHARSET', 'utf8'); -define('DBPREFIX', 'vfs_'); +define('DBPREFIX', 'jg_'); ### define your pepper for password security define('PEPPER_IS_FILE', false); @@ -26,5 +26,5 @@ define('PEPPER', 'somelongstringhere'); # define('SCHEME', 'https://'); ### hostname -define('HOST', 'jungegemeinde.iamfabulous.de'); -define('DOMAIN', 'https://jungegemeinde.iamfabulous.de'); +# define('HOST', 'jungegemeinde.iamfabulous.de'); +# define('DOMAIN', 'https://jungegemeinde.iamfabulous.de'); diff --git a/bootstrap/functions.php b/bootstrap/functions.php index 8c998fc..60408a2 100644 --- a/bootstrap/functions.php +++ b/bootstrap/functions.php @@ -22,3 +22,217 @@ function failure($reason, $httpcode, $ajax = true, $heading = NULL){ # exit the script here exit; } + +function print_login(){ +if(isset($_GET["goto"]) && $_GET["goto"] != "") + $goto = $_GET["goto"]; +else + $goto = "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> + +<!-- 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"> + </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"> + </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">Log In</button> + </div> +</div> + +</fieldset> +</form> +</div> +<?php +} + +function print_index(){ +?> + <h1>Junge Gemeinde Adlershof</h1> + </div> + <div class="row"> + </div> +<?php +} + +function print_list(){ + global $db; + + $result = $db->doQuery("SELECT * FROM " . DBPREFIX . "member;"); +?> + <h1>Adress Liste</h1> + <br> + </div> + <div class="row"> + <table width='60%' class='table table-striped'> + <thead> + <tr> + <th><p>#</p></th> + <th><p>Name</p></th> + <th><p>Adresse</p></th> + <th><p>Telefon</p></th> + <th><p>Handynummer</p></th> + <th><p>E-Mail</p></th> + <th><p>Geburtstag</p></th> + <th><p>ändern</p></th> + </tr> + </thead> + <tbody> + <?php + $count = 1; + while ( $row = $result->fetch_array(MYSQLI_ASSOC) ){ + echo "<tr> + <td>$count</td> + <td>".htmlentities($row['name'])."</td> + <td>".htmlentities($row['adresse'])."</td> + <td>".htmlentities($row['telefonnummer'])."</td> + <td>".htmlentities($row['handynummer'])."</td> + <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>"; + $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> + <form method="POST" action="/?page=add"> + <button id="singlebutton" class="btn btn-info" type="submit">Füge jemanden hinzu</button> + </form> +</div> +</div> + +<?php +} + +function print_update_list($id){ + global $db; + + $sql = $db->prepare("SELECT * FROM " . DBPREFIX . "member WHERE member_id = %d", $id); + $result = $db->doQuery($sql); + if(!$result){ + echo "Fail!"; + exit; + } + while ( $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'> + <table class='table'> + <thead> + <tr> + <th>Name</th> + <th>Adresse</th> + <th>Telefon</th> + </tr> + </thead> + <tbody> + <tr> + <td><input type='text' name='name' value='<?php echo htmlentities($row['name']); ?>'></td> + <td><input type='text' name='adresse' value='<?php echo htmlentities($row['adresse']); ?>'></td> + <td><input type='text' name='telefonnummer' value='<?php echo htmlentities($row['telefonnummer']); ?>'></td> + </tr> + </tbody> + <thead> + <tr> + <th>Handynummer</th> + <th>E-Mail</th> + <th>Geburtstag</th> + </tr> + <tbody> + <tr> + <td><input type='text' name='handynummer' value='<?php echo htmlentities($row['handynummer']); ?>'></td> + <td><input type='text' name='email' value='<?php echo htmlentities($row['email']); ?>'></td> + <td><input type='text' name='geburtstag' value='<?php echo htmlentities($row['geburtstag']); ?>'></td> + </tr> + </tbody> + </table> + <button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Ändere!</button> + </form> + </div> +<?php + } +} + +function print_add_entry_to_list(){ +?> + <h1>Füge die Daten hinzu</h1> + </div> + <div class="row"> + <form method='POST' action='/?page=action&task=add&goto=liste'> + <table class='table'> + <thead> + <tr> + <th>Name</th> + <th>Adresse</th> + <th>Telefon</th> + </tr> + </thead> + <tbody> + <tr> + <td><input type='text' name='name' placeholder='Name'></td> + <td><input type='text' name='adresse' placeholder='Adresse'></td> + <td><input type='text' name='telefonnummer' placeholder='Telefonnummer'></td> + </tr> + </tbody> + <thead> + <tr> + <th>Handynummer</th> + <th>E-Mail</th> + <th>Geburtstag</th> + </tr> + <tbody> + <tr> + <td><input type='text' name='handynummer' placeholder='Handynummer'></td> + <td><input type='text' name='email' placeholder='E-Mail'></td> + <td><input type='text' name='geburtstag' placeholder='Geburtstag'></td> + </tr> + </tbody> + </table> + <button id="singlebutton" name="singlebutton" class="btn btn-info" type="submit">Hinzufügen!</button> + </form> + </div> +<?php +} + +function _add_entry(){ + 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']); + if( ! $db->doQuery($sql) ) + return false; + else + return true; +} + +function print_404(){ + header($_SERVER['HTTP_PROTOCOL'] . ' 404 Not Found'); +?> +<?php +} diff --git a/bootstrap/index.php b/bootstrap/index.php index fbe4d8d..32b4a97 100644 --- a/bootstrap/index.php +++ b/bootstrap/index.php @@ -1,8 +1,12 @@ <?php -require_once( dirname(__FILE__) . '/bootstrap.php'); ob_start(); +# if we kann redirect user mit the ?goto variable +$redirect = true; + +require_once( dirname(__FILE__) . '/bootstrap.php'); + $db = new db(); $user = new jg(); ?> @@ -10,9 +14,11 @@ $user = new jg(); <html> <head> <meta charset="utf-8"> + <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> + <link rel ="stylesheet" href="/static/style.css"> + <style>.dl-horizontal dt{white-space: normal;} .btn-info{background-color:#3083D6;}</style> <title>Junge Gemeinde Adlershof</title> <link rel='shortcut icon' href='/favicon.ico' type='image/x-icon'> - <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <noscript><style>.navbar{margin-bottom:0;}</style></noscript> </head> @@ -23,50 +29,43 @@ require_once 'static/header.php'; <div class="text-center"> <div class="row"> <?php -if ( ! $user->isLoggedIn() ){ -?> -<form class="form-horizontal"> -<fieldset> -<!-- Form Name --> -<legend><h1>Junge Gemeinde Adlershof</h1></legend> + if($_GET["page"] == "" || $_GET["page"] == "index") + print_index(); + else{ + switch($_GET["page"]){ + case("login"): + print_login(); + break; + case("liste"): + print_list(); + break; -<!-- 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"> - <span class="help-block">Required for login.</span> - </div> -</div> + case("update"): + print_update_list($_GET['id']); + break; + case("add"): + print_add_entry_to_list(); + break; + case("404"): + print_404(); + break; + case("action"): + require_once 'action.php'; + break; + default: + print_index(); + } + } -<!-- 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"> - <span class="help-block">Required for login.</span> - </div> +/* +if ( isset($_GET['goto']) && $_GET['goto'] != "" && $redirect ){ + header($_SERVER['SERVER_PROTOCOL'] . ' 302 Moved'); + header('Location: /?page='.$_GET['goto']); +} +*/ +?> </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">Log In</button> - </div> </div> - -</fieldset> -</form> -<?php -} else { -?> - <h1>Junge Gemeinde Adlershof</h1> - </div> - <div class="row"> - <p>Welcome!</p> - </div> <?php require_once 'static/footer.php'; -} diff --git a/bootstrap/setup.php b/bootstrap/setup.php deleted file mode 100644 index b984253..0000000 --- a/bootstrap/setup.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -# init file to set up the database -# TODO: pretty html - -$db = new db(); -$db->createTables(); -$db->close(); - -echo "<p>Successfully created the database.</p>"; - -# rename this file to avoid setting up the tables twice -rename(ABSPATH . 'setup.php', ABSPATH . '_setup.php'); diff --git a/bootstrap/static/header.php b/bootstrap/static/header.php index 37c36ab..a7a5042 100644 --- a/bootstrap/static/header.php +++ b/bootstrap/static/header.php @@ -7,18 +7,18 @@ <span class="icon-bar"></span> <span class="icon-bar"></span> </button> - <a class="navbar-brand" href="/">Home</a> + <a class="navbar-brand" href="/?page=index">Home</a> </div> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="nav navbar-nav"> <li> - <a href="/liste" >Adressliste</a> + <a href="/?page=liste" >Adressliste</a> </li> <li> <a href="https://lists.iamfabulous.de/mailman/listinfo/jungegemeinde" >E-Mail Verteiler</a> </li> <li> - <a href="/logout" >Logout</a> + <a href="/?page=logout" >Logout</a> </li> </ul> </div> diff --git a/bootstrap/static/style.css b/bootstrap/static/style.css new file mode 100644 index 0000000..5821df4 --- /dev/null +++ b/bootstrap/static/style.css @@ -0,0 +1,66 @@ +html { + position: relative; + min-height: 100%; +} + +body { + margin-bottom: 60px; +} + +a { + color: #3083D6; +} + +/* navbar */ + +.navbar-default { + background-color: #3083D6 ; + border-color: #3083D6 ; + background: #3083D6 ; +} + +.navbar-default .navbar-brand { + color: white; +} + +.navbar-default .navbar-brand:hover, +.navbar-default .navbar-brand:focus { +} + +.navbar-default .navbar-nav > li > a { + color: white; +} + + +/* footer */ + +.footer { + background-color: #3083D6 ; + border-color: #3083D6 ; + background: #3083D6 ; + color: white ; + position: absolute; + bottom: 0; + width: 100%; +} + +#copyright-text { + color: white; +} + +/* noscript */ + +.noscript { + background-color: red; + color: white; +} + +.table-center { + margin: 0 auto !important; + float: none !important; +} + +.disabled { + color: #5E5E5E; + text-decoration: line-through; +} |
