Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
basic setup for the application
Browse files Browse the repository at this point in the history
  • Loading branch information
Luuk van Houdt committed Jan 25, 2016
1 parent 5521a2b commit 5effe19
Show file tree
Hide file tree
Showing 21 changed files with 277 additions and 143 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.sass-cache
.idea
connect.php
inc/connect.php
36 changes: 0 additions & 36 deletions admin.php

This file was deleted.

18 changes: 0 additions & 18 deletions connect.php

This file was deleted.

52 changes: 41 additions & 11 deletions css/main.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* line 5, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 5, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
Expand All @@ -20,45 +20,45 @@ time, mark, audio, video {
vertical-align: baseline;
}

/* line 22, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 22, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
html {
line-height: 1;
}

/* line 24, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 24, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
ol, ul {
list-style: none;
}

/* line 26, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 26, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
table {
border-collapse: collapse;
border-spacing: 0;
}

/* line 28, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 28, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
caption, th, td {
text-align: left;
font-weight: normal;
vertical-align: middle;
}

/* line 30, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 30, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
q, blockquote {
quotes: none;
}
/* line 103, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 103, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
q:before, q:after, blockquote:before, blockquote:after {
content: "";
content: none;
}

/* line 32, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 32, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
a img {
border: none;
}

/* line 116, ../../../../Ruby22-x64/lib/ruby/gems/2.2.0/gems/compass-core-1.0.3/stylesheets/compass/reset/_utilities.scss */
/* line 116, ../../../../../../usr/local/lib/ruby/gems/2.1.0/gems/compass-core-1.0.1/stylesheets/compass/reset/_utilities.scss */
article, aside, details, figcaption, figure, footer, header, hgroup, main, menu, nav, section, summary {
display: block;
}
Expand All @@ -83,13 +83,43 @@ h1, h2, h3, h4, h5, h6 {
width: 40%;
display: block;
border: 5px solid #D1DBBD;
height: 100px;
margin: auto;
-moz-border-radius: 10px;
-webkit-border-radius: 10px;
border-radius: 10px;
}
/* line 19, ../scss/_common.scss */
/* line 18, ../scss/_common.scss */
.block h1 {
font-size: 24px;
}
/* line 21, ../scss/_common.scss */
.block .switch {
display: inline-block;
background-color: #D1DBBD;
}
/* line 25, ../scss/_common.scss */
.block .switch.active .on {
cursor: default;
background-color: #3E606F;
}
/* line 29, ../scss/_common.scss */
.block .switch.active .off {
cursor: pointer;
background-color: transparent;
}
/* line 34, ../scss/_common.scss */
.block .switch a {
width: 30px;
padding: 8px;
color: #FCFFF5;
line-height: 100%;
display: inline-block;
}
/* line 40, ../scss/_common.scss */
.block .switch a.on {
cursor: pointer;
}
/* line 43, ../scss/_common.scss */
.block .switch a.off {
background-color: #3E606F;
}
7 changes: 0 additions & 7 deletions header.php

This file was deleted.

51 changes: 51 additions & 0 deletions html/admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div class="block">
<h1>Beheerders paneel</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<button name="logout" type="submit">Uitloggen</button>
</form>
</div>
<div class="block">
<h2>Domotica systemen</h2>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input name="city" type="text" placeholder="Stad" />
<input name="street" type="text" placeholder="Straat" />
<input name="house" type="text" placeholder="Huisnummer" />
<button name="search" type="submit">Zoeken</button>
</form>
<?php
if (isset($_POST['search'])) {
$q = $pdo->prepare('SELECT *
FROM systems
WHERE city LIKE :city AND
street LIKE :street AND
house LIKE :house
');
$q->execute(array(
':city' => '%'.$_POST['city'].'%',
':street' => '%'.$_POST['street'].'%',
':house' => '%'.$_POST['house'].'%',
));
$rows = $q->fetchAll();
} else {
$q = $pdo->prepare('SELECT * FROM systems LIMIT 0,10');
$q->execute();
$rows = $q->fetchAll();
}
if ($rows) :
foreach ($rows as $row) :
?>
<div class="row">
<span class="status <?php print ($row['status']) ? 'on' : 'off'; ?>"></span>
<span class="city"><?php print $row['city']; ?></span>
<span class="street"><?php print $row['street']; ?></span>
<span class="house"><?php print $row['house']; ?></span>
</div>
<?php
endforeach;
else:
?>
<div class="no-results">Geen domotica systemenen gevonden.</div>
<?php
endif;
?>
</div>
15 changes: 15 additions & 0 deletions html/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="block">
<h1>Inloggen</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
<input type="text" name="username" placeholder="Gebruikersnaam" />
</p>
<p>
<input type="password" name="password" placeholder="Wachtwoord" />
</p>
<p>
<button type="reset">reset</button>
<button name="login" type="submit">login</button>
</p>
</form>
</div>
38 changes: 38 additions & 0 deletions html/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="block">
<h1>Gebruikerspaneel</h1>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<section class="dotted">
<ul>
<li><strong>Woonplaats:</strong><span><?php print $_SESSION['system']['city']; ?></span></li>
<li><strong>Straatnaam:</strong><span><?php print $_SESSION['system']['street']; ?></span></li>
<li><strong>Huisnummer:</strong><span><?php print $_SESSION['system']['house']; ?></span></li>
</ul>
</section>
<section class="lights">
<h2>Verlichting</h2>
<?php
$lights = $_SESSION['system']['lights'];
$lights_class = ($lights==1) ? ' active' : '';
?>
<div class="switch<?php print $lights_class; ?>">
<a class="off">uit</a>
<a class="on">aan</a>
<input name="lights" type="hidden" value="<?php print $lights; ?>" />
</div>
</section>
<section class="camera">
<h2>Camera</h2>
<?php
$camera = $_SESSION['system']['camera'];
$camera_class = ($camera==1) ? ' active' : '';
?>
<div class="switch<?php print $camera_class; ?>">
<a class="off">uit</a>
<a class="on">aan</a>
<input name="camera" type="hidden" value="<?php print $camera; ?>" />
</div>
</section>
<button name="logout" type="submit">Uitloggen</button>
<button name="save" type="submit">Opslaan</button>
</form>
</div>
File renamed without changes.
48 changes: 48 additions & 0 deletions inc/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
session_start();

include 'connect.php';

if (isset($_POST['login'])) {
if (!empty($_POST['username']) and !empty($_POST['password'])) {
$q = $pdo->prepare('SELECT user_id, username, role FROM users WHERE username = :user AND password = :pass');
$q->execute(array(
':user' => $_POST['username'],
':pass' => md5($_POST['password']),
));
$r = $q->fetch();

if ($r) {
// Logged in successfully
$_SESSION['user'] = $r;
if ($r['role'] == 0) {
$q = $pdo->prepare('SELECT * FROM systems WHERE user_id = :id');
$q->execute(array(':id' => $r['user_id']));
$r = $q->fetch();
if ($r) {
// Open user panel
$_SESSION['system'] = $r;
header('Location: '.$_SERVER['PHP_SELF']);
} else {
$error = 'U account is niet gekoppeld aan een domotica systeem.';
}
} else {
// Open admin panel
header('Location: '.$_SERVER['PHP_SELF']);
}
} else {
$error = 'Verkeerde gebruikersnaam of wachtwoord.';
}
} else {
$error = 'Gebruikersnaam of wachtwoord is niet ingevuld.';
}
}

if (isset($_POST['logout'])) {
session_destroy();
header('Location: '.$_SERVER['PHP_SELF']);
}

if (isset($_POST['save'])) {
var_dump($_POST);
}
12 changes: 12 additions & 0 deletions inc/header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
require ABSPATH.'inc/functions.php';
?>
<html>
<head>
<title>Alpha Domotica</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>

35 changes: 19 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<?php
require 'functions.php';
require_once('header.php');

define('ABSPATH', getcwd().'/');

?>
<div class="block">
<h1>Inloggen</h1>
<form action="" method="post">
<input type="text" name="username" />
<button type="reset">reset</button>
</form>
<form action="" method="post">
<input type="password" name="password"/>
<button type="submit">login</button>
</form>
</div>
require_once(ABSPATH.'inc/header.php');


// Check if the user made an error
if (!empty($error)) {
print '<div class="status error">'.$error.'</div>';
}

<?php
require_once('footer.php');
// Check if the user is logged in
if (isset($_SESSION['user'])) {
// Check if the user is an admin
if ($_SESSION['user']['role'] == 1) {
include_once(ABSPATH.'html/admin.php');
} else {
include_once(ABSPATH.'html/user.php');
}
} else {
include_once(ABSPATH.'html/login.php');
}

require_once(ABSPATH.'inc/footer.php');
4 changes: 4 additions & 0 deletions js/jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit 5effe19

Please sign in to comment.