Commit 15421a6a by sopham

delete tasks by id, php user authentication

parent e476aa2f
<?php
session_start();
require_once "dbconnection.php";
if ($stmt = $link->prepare('SELECT ID,password FROM users WHERE username= ?')) {
$stmt->bind_param('s', $_POST['username']);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->bind_result($id, $password);
$stmt->fetch();
if ($_POST['password'] === $password) {
session_regenerate_id();
$_SESSION['loggedin'] = TRUE;
$_SESSION['name'] = $_POST['username'];
$_SESSION['id'] = $id;
header('Location:index.php');
} else {
echo "Incorrect password";
}
}
$stmt->close();
}
?>
<?php <?php
//connection data
$server = "anysql.itcollege.ee"; $server = "anysql.itcollege.ee";
$user = "team4"; $user = "team4";
$password = "rw_353MIl_e"; $password = "rw_353MIl_e";
$database = "WT_4"; $database = "WT_4";
//connect using mysqli object-oriented style
$link = new mysqli($server, $user, $password, $database); $link = new mysqli($server, $user, $password, $database);
if($link -> connect_error) die("Connecion to DB failed: ". $link -> connect_error);
//error-handling
if($link -> connect_error)
die("Connecion to DB failed: ". $link -> connect_error);
?> ?>
<?php <?php
include_once "dbconnection.php"; include_once "dbconnection.php";
/*
$link = new mysqli($server, $user, $password, $database);
if($link -> connect_error) die("Connecion to DB failed: ". $link -> connect_error);
$query = "SELECT task FROM toDoList;"; $query = "TRUNCATE TABLE toDoList;";
$result = $link -> query($query); $result = $link -> query($query);
if (!$result) die ("Database access failed"); if($result->num_rows <= 0) {
*/ echo "No task was deleted";
$query = "TRUNCATE TABLE toDoList;";
if(!$link->query($query)) {
echo "(".$link->errno.")".$link->error;
} }
$link -> close();
?> ?>
<?php <?php
include_once "dbconnection.php"; include_once "dbconnection.php";
$query ="DELETE FROM toDoList WHERE task=?"; $query ="DELETE FROM toDoList WHERE ID=?";
$query = $link->prepare($query); $query = $link->prepare($query);
$query->bind_param('s', $_GET['task']); $query->bind_param('s', $_GET['id']);
$query->execute(); $query->execute();
$query->close(); $query->close();
......
...@@ -2,17 +2,20 @@ ...@@ -2,17 +2,20 @@
header('Content-type: application/json'); header('Content-type: application/json');
include_once "dbconnection.php"; include_once "dbconnection.php";
$query = "SELECT task FROM toDoList;"; $query = "SELECT ID,task FROM toDoList;";
$result = $link -> query($query); $result = $link -> query($query);
if (!$result) die ("Database access failed"); if (!$result) die ("Database access failed");
$data = array(); $data = array();
for ($i = 0; $i < $result->num_rows; ++$i) { for ($i = 0; $i < $result->num_rows; ++$i) {
//$task = array();
$row = $result->fetch_array(MYSQLI_NUM); $row = $result->fetch_array(MYSQLI_NUM);
array_push($data, $row[0]); $data[$row[0]] = $row[1];
} }
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode($data); echo json_encode($data);
$link->close(); $link->close();
?> ?>
var i = 0;
//var i = 0;
/*
//add new row to list after submitting //add new row to list after submitting
function addRow(){ function addRow(){
if (document.getElementById('add-task').value!=''){ if (document.getElementById('add-task').value!=''){
i++; i++;
var title = document.getElementById('add-task').value; var title = document.getElementById('add-task').value;
var node = document.createElement('div'); var node = document.createElement('div');
node.innerHTML = '<input id="option' + i + '" type="checkbox" class="hidden" name="checkbox"><label for="option' + i + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">'+ title +'</span>'; node.innerHTML = '<input id="' + i + '" type="checkbox" class="hidden" name="checkbox"><label for="' + i + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">'+ title +'</span>';
document.getElementById('doList').appendChild(node); var lastElement = parseInt(document.getElementById("doList").lastElementChild.getAttribute("id"));
if (!isNaN(lastElement)) {
node.setAttribute("id", lastElement + 1);
}
else {
node.setAttribute("id", 0);
}
$.ajax({
dataType: 'JSON',
url: 'get-id.php',
success: function(data){
})
//node.setAttribute("id", new_id);
document.getElementById('doList').appendChild(node);
} }
} }
*/
//delete all tasks //delete all tasks
function deleteAll() { function deleteAll() {
...@@ -43,23 +59,46 @@ $("#imageUpload").change(function() { ...@@ -43,23 +59,46 @@ $("#imageUpload").change(function() {
readURL(this); readURL(this);
}); });
//display input from database
$(document).ready(function() { $(document).ready(function() {
//display input from the database
$.ajax({ $.ajax({
dataType: 'JSON', dataType: 'JSON',
url: 'display.php', url: 'display.php',
success: function(data) { success: function(data) {
var items = []; //var items = [];
$.each( data, function(key, val) { $.each( data, function(key, val) {
i++; //i++;
var title = val; //var title = val
var node = document.createElement('div'); var node = document.createElement('div');
node.innerHTML = '<input id="option' + i + '" type="checkbox" class="hidden" name="checkbox"><label for="option' + i + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + title + '</span>'; node.innerHTML = '<input id="' + key + '" type="checkbox" class="hidden" name="checkbox"><label for="' + key + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + val + '</span>';
document.getElementById('doList').appendChild(node); document.getElementById('doList').appendChild(node);
}) })
} }
}); });
}); });
/*
//add id into the each task after load page
$.ajax({
dataType:'JSON',
url: 'add-id.php',
success: function(data) {
var i = 0;
var id = [];
$.each(data, function(key, val) {
id.push(val);
})
$('#doList').children('div').each(function () {
if($(this).attr('class') == "progress-container") { return; }
else {
$(this).attr('id', id[i]);
i++;
}
})
}
});
});
*/
//delete completed tasks //delete completed tasks
$(document).ready(function() { $(document).ready(function() {
...@@ -70,7 +109,9 @@ $(document).ready(function() { ...@@ -70,7 +109,9 @@ $(document).ready(function() {
$.ajax({ $.ajax({
type: "GET", type: "GET",
url: "delete-complete.php", url: "delete-complete.php",
data: {task: $(this).next().children(".check--label-text").text()} data: {
id: $(this).next().attr("for")
}
}); });
$(this).parent().remove(); $(this).parent().remove();
}); });
......
...@@ -7,8 +7,16 @@ $("#addAction").submit(function(event) { ...@@ -7,8 +7,16 @@ $("#addAction").submit(function(event) {
type:"POST", type:"POST",
data:{ data:{
"task": task }, "task": task },
success: function() { success: function(data) {
$("#add-task").val(""); $("#add-task").val("");
var new_id = data;
if (document.getElementById('add-task').value='') {
var title = document.getElementById('add-task').value();
var node = document.createElement('div');
node.innerHTML = '<input id="' + new_id + '" type="checkbox" class="hidden" name="checkbox"><label for="' + new_id + '" class="check--label"><span class="check--label-box"></span><span class="check--label-text">' + title + '</span>';
node.setAttribute("id", new_id);
document.getElementById('doList').appendChild(node);
}
} }
}); });
}); });
......
<?php
session_start();
if(!isset($_SESSION['loggedin'])) {
session_destroy();
$params = session_get_cookie_params();
setcookie(session_name(), '', 0, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
header('Location: login_page.php');
exit();
}
?>
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
...@@ -29,9 +39,9 @@ ...@@ -29,9 +39,9 @@
<div class="extra-content" id="extraContent"> <div class="extra-content" id="extraContent">
<a href="javascript:window.print()"><i class="glyphicon glyphicon-print"></i> Print List</a> <a href="javascript:window.print()"><i class="glyphicon glyphicon-print"></i> Print List</a>
<a id="delete-complete"><i class="fa fa-trash w3-large"></i> Completed Tasks</a> <a id="delete-complete"><i class="fa fa-trash w3-large"></i> Completed Tasks</a>
<a onclick="deleteAll();" id="delete-button"><i class="fa fa-trash w3-large"></i> Delete All</a> <a id="delete-button"><i class="fa fa-trash w3-large"></i> Delete All</a>
</div><br> </div><br>
<form action="login_check.php" method="POST" id="action"> <form action="logout.php" method="POST" id="action">
<input type="submit" class="logout-button" name="logout"value="Logout"> <input type="submit" class="logout-button" name="logout"value="Logout">
</form> </form>
</div> </div>
......
<?php
if(isset($_POST['logout'])) {
session_name($user);
session_destroy();
header('Location: login_page.php');
exit;
}
if(isset($_POST['add-button'])){
$addTask = $_POST['add-task'];
$file = fopen("taskList.txt","a+") or die("Unable to open file");
$s = $addTask."\r\n";
fputs($file,$s) or die("Unable to open save");
fclose($file);
header('Location: index.php');
}
?>
...@@ -3,10 +3,11 @@ include_once "dbconnection.php"; ...@@ -3,10 +3,11 @@ include_once "dbconnection.php";
$query = "INSERT INTO toDoList (task) VALUES (?) "; $query = "INSERT INTO toDoList (task) VALUES (?) ";
$query = $link->prepare($query); $query = $link->prepare($query);
$query -> bind_param('s', $_POST['task']);
$query -> execute();
$query->bind_param('s', $_POST['task']); $last_id = mysqli_insert_id($link);
$query ->execute(); echo $last_id;
$query -> close(); $query -> close();
$link -> close(); $link -> close();
?> ?>
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<div class="card"> <div class="card">
<form name="input" action="login_check.php" method="POST"> <form name="input" action="authentication.php" method="POST">
<label for="username">Username</label> <label for="username">Username</label>
<input type="text" id="username" name="username" pattern="[a-zA-Z][a-zA-Z0-9-_\.]{1,20}" required> <input type="text" id="username" name="username" pattern="[a-zA-Z][a-zA-Z0-9-_\.]{1,20}" required>
<br> <br>
<label for="password">Password&nbsp</label> <label for="password">Password&nbsp</label>
<input type="password" id="password" name="password" autocomplete="off" required> <input type="password" id="password" name="password" autocomplete="off" required>
......
<?php
session_start();
session_unset();
session_destroy();
$params = session_get_cookie_params();
setcookie(session_name(), '', 0, $params['path'], $params['domain'], $params['secure'], isset($params['httponly']));
header("Location: login_page.php");
?>
@charset "UTF-8";
@charset "UTF-8";
* {
box-sizing: border-box; * {
font-family: 'Roboto Slab', serif; box-sizing: border-box;
font-size: 20px; font-family: 'Roboto Slab', serif;
} font-size: 20px;
}
@media print{
#form { @media print{
overflow-y:hidden; #form {
} overflow-y:hidden;
#side { }
display: none; } #side {
#action{ display: none; }
display: none; #action{
} display: none;
#addAction{ }
display: none; #addAction{
} display: none;
#buttonExtra{ }
display: none; #buttonExtra{
} display: none;
#extraContent{ }
display: none; #extraContent{
} display: none;
#dropContent{ }
display: none; #dropContent{
} display: none;
#doList { }
display: block; #doList {
position: absolute; display: block;
top: 10px; position: absolute;
left: 20px; top: 10px;
} left: 20px;
} }
}
@media screen and (max-width: 600px) {
body { @media screen and (max-width: 600px) {
float: none; body {
} float: none;
} }
}
.row {
margin: 0 -5px; .row {
display: flex; margin: 0 -5px;
width: 100%; display: flex;
min-width: 1050px; width: 100%;
} min-width: 1050px;
}
.main {
width: 100%; .main {
float:none; width: 100%;
} float:none;
}
.card {
height: 100%; .card {
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2); height: 100%;
padding: 20px; box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
text-align: center; padding: 20px;
background-color: #f1f1f1; text-align: center;
margin: 10px 10px 10px 10px; background-color: #f1f1f1;
} margin: 10px 10px 10px 10px;
}
.list-card {
height: 35%; .list-card {
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2); height: 35%;
padding: 12px; box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
text-align: center; padding: 12px;
font-family: 'Roboto Slab', serif; text-align: center;
background-color: #f1f1f1; font-family: 'Roboto Slab', serif;
text-align: center; background-color: #f1f1f1;
margin: 10px 10px 10px 10px; text-align: center;
} margin: 10px 10px 10px 10px;
}
.task-card {
cursor: pointer; .task-card {
width: 220px; cursor: pointer;
height: 64%; width: 220px;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2); height: 64%;
padding: 30px; box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
margin: 10px 10px 10px 10px; padding: 30px;
text-align: center; margin: 10px 10px 10px 10px;
background-color: #f1f1f1; text-align: center;
} background-color: #f1f1f1;
}
.side {
padding: 0px 5px 0px 30px; .side {
} padding: 0px 5px 0px 30px;
}
.extra-content {
font-family: 'Roboto Slab', serif; .extra-content {
width: 100%; font-family: 'Roboto Slab', serif;
border-radius: 6px; width: 100%;
} border-radius: 6px;
}
.extra-content a {
color: black; .extra-content a {
padding: 15px 16px; color: black;
display: block; padding: 15px 16px;
border-radius: 6px; display: block;
} border-radius: 6px;
}
.extra-content a:hover {
color: white; .extra-content a:hover {
background-color:#b198e6b9; color: white;
} background-color:#b198e6b9;
}
.logout-button {
background-color: #9370DB; .logout-button {
font-family: 'Roboto Slab', serif; background-color: #9370DB;
width: 100%; font-family: 'Roboto Slab', serif;
padding: 10px; width: 100%;
border-radius: 6px; padding: 10px;
border: none; border-radius: 6px;
transition: all 0.5s; border: none;
cursor: pointer; transition: all 0.5s;
display: inline-block; cursor: pointer;
color: white; display: inline-block;
} color: white;
.logout-button:hover{ }
background: red; .logout-button:hover{
} background: red;
}
input[type=text] {
width: 70%; input[type=text] {
box-sizing: border-box; width: 70%;
border: 2px solid #9370DB; box-sizing: border-box;
border-radius: 6px; border: 2px solid #9370DB;
background-color: white; border-radius: 6px;
padding: 12px 0 12px 40px; background-color: white;
float:left; padding: 12px 0 12px 40px;
margin-left: 90px; float:left;
margin-top: 60px; margin-left: 90px;
} margin-top: 60px;
}
.add-button {
background-color:rgb(83, 68, 170); .add-button {
font-family: 'Roboto Slab', serif; background-color:rgb(83, 68, 170);
width: 10%; font-family: 'Roboto Slab', serif;
color: white; width: 10%;
padding: 14px; color: white;
border-radius: 6px; padding: 14px;
border: none; border-radius: 6px;
transition: all 0.5s; border: none;
cursor: pointer; transition: all 0.5s;
float: left; cursor: pointer;
margin-top: 60px; float: left;
margin-left: 5px; margin-top: 60px;
} margin-left: 5px;
}
.add-button:hover{
background-color: #9370DB; .add-button:hover{
color: white; background-color: #9370DB;
} color: white;
}
.task-board {
border: 6px; .task-board {
margin-top: 150px; border: 6px;
margin-left: 90px; margin-top: 150px;
width: 80%; margin-left: 90px;
background-color: white; width: 80%;
border-radius: 15px; background-color: white;
overflow-y: scroll; border-radius: 15px;
min-width: 200px; overflow-y: scroll;
height: 460px; min-width: 200px;
} height: 460px;
}
.checkmark {
position: absolute; .checkmark {
top: 9px; position: absolute;
left: 15px; top: 9px;
height: 25px; left: 15px;
width: 25px; height: 25px;
border-radius: 50%; width: 25px;
background-color: #eee; border-radius: 50%;
} background-color: #eee;
}
.hidden {
position: absolute; .hidden {
appearance: none; position: absolute;
} appearance: none;
}
.check--label {
display: flex; .list {
justify-content: flex-start; display: flex;
flex-direction: row; }
flex-wrap: nowrap;
align-items: center; .check--label {
margin-top: 15px; display: flex;
height: 40px; justify-content: flex-start;
} flex-direction: row;
flex-wrap: nowrap;
.check--label-box { align-items: center;
display: flex; margin-top: 15px;
align-self: center; height: 40px;
position: relative; }
height: 25px;
width: 25px; .check--label-box {
margin: 0 20px; display: flex;
border: 2px solid rgb(83, 68, 170); align-self: center;
cursor: pointer; position: relative;
border-radius: 50%; height: 25px;
} width: 25px;
margin: 0 20px;
.check--label-text { border: 2px solid rgb(83, 68, 170);
position: relative; cursor: pointer;
display: flex; border-radius: 50%;
cursor: pointer; }
align-self: center;
padding: 20px; .check--label-text {
font-size: 22px; position: relative;
border-left: 1px solid #ecf0f1; display: flex;
} cursor: pointer;
align-self: center;
.check--label-text:after { padding: 20px;
content: ''; font-size: 22px;
display: block; border-left: 1px solid #ecf0f1;
width: 0%; }
height: 2px;
background-color: #000; .check--label-text:after {
position: absolute; content: '';
top: 50%; display: block;
left: 7.5%; width: 0%;
transform: translateY(-50%); height: 2px;
transition: width 100ms ease-in-out; background-color: #000;
} position: absolute;
top: 50%;
.hidden:checked + .check--label { left: 7.5%;
background-color: #fff; transform: translateY(-50%);
} transition: width 100ms ease-in-out;
}
.hidden:checked + .check--label .check--label-box {
background-color: rgb(83, 68, 170); .hidden:checked + .check--label {
} background-color: #fff;
.hidden:checked + .check--label .check--label-box:after { }
content: '';
display: block; .hidden:checked + .check--label .check--label-box {
position: absolute; background-color: rgb(83, 68, 170);
top: 3px; }
left: 7px; .hidden:checked + .check--label .check--label-box:after {
width: 7px; content: '';
height: 12px; display: block;
border: solid white; position: absolute;
border-width: 0 3px 3px 0; top: 3px;
transform: rotate(45deg); left: 7px;
} width: 7px;
height: 12px;
.hidden:checked + .check--label .check--label-text:after { border: solid white;
width: 85%; border-width: 0 3px 3px 0;
} transform: rotate(45deg);
}
.avatar-upload {
position: relative; .hidden:checked + .check--label .check--label-text:after {
max-width: 205px; width: 85%;
margin: 50px auto; }
}
.avatar-upload {
.avatar-edit { position: relative;
position: absolute; max-width: 205px;
right: 12px; margin: 50px auto;
z-index: 1; }
top: -20px;
} .avatar-edit {
position: absolute;
.avatar-upload .avatar-edit input { right: 12px;
display: none; z-index: 1;
} top: -20px;
}
.avatar-upload input + label {
display: inline-block; .avatar-upload .avatar-edit input {
width: 34px; display: none;
height: 34px; }
margin-bottom: 0;
border-radius: 100%; .avatar-upload input + label {
background: #FFFFFF; display: inline-block;
border: 1px solid transparent; width: 34px;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12); height: 34px;
cursor: pointer; margin-bottom: 0;
font-weight: normal; border-radius: 100%;
transition: all .2s ease-in-out; background: #FFFFFF;
} border: 1px solid transparent;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
.avatar-upload input + label:hover { cursor: pointer;
background: #f1f1f1; font-weight: normal;
border-color: #d6d6d6; transition: all .2s ease-in-out;
} }
.avatar-upload input + label:after { .avatar-upload input + label:hover {
content: "\f040"; background: #f1f1f1;
font-family: 'FontAwesome'; border-color: #d6d6d6;
color: #757575; }
position: absolute;
top: 2px; .avatar-upload input + label:after {
left: 0px; content: "\f040";
right: 0px; font-family: 'FontAwesome';
text-align: center; color: #757575;
margin: auto; position: absolute;
} top: 2px;
left: 0px;
.avatar-preview { right: 0px;
width: 190px; text-align: center;
height: 190px; margin: auto;
position: relative; }
top: -35px;
border-radius: 100%; .avatar-preview {
border: 6px solid #F8F8F8; width: 190px;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1); height: 190px;
} position: relative;
top: -35px;
.avatar-preview > div { border-radius: 100%;
width: 100%; border: 6px solid #F8F8F8;
height: 100%; box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
border-radius: 50%; }
background-size: cover;
background-repeat: no-repeat; .avatar-preview > div {
background-position: center; width: 100%;
height: 100%;
border-radius: 50%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment