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
//connection data
$server = "anysql.itcollege.ee";
$user = "team4";
$password = "rw_353MIl_e";
$database = "WT_4";
//connect using mysqli object-oriented style
$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
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);
if (!$result) die ("Database access failed");
*/
$query = "TRUNCATE TABLE toDoList;";
if(!$link->query($query)) {
echo "(".$link->errno.")".$link->error;
if($result->num_rows <= 0) {
echo "No task was deleted";
}
$link -> close();
?>
<?php
include_once "dbconnection.php";
$query ="DELETE FROM toDoList WHERE task=?";
$query ="DELETE FROM toDoList WHERE ID=?";
$query = $link->prepare($query);
$query->bind_param('s', $_GET['task']);
$query->bind_param('s', $_GET['id']);
$query->execute();
$query->close();
......
......@@ -2,17 +2,20 @@
header('Content-type: application/json');
include_once "dbconnection.php";
$query = "SELECT task FROM toDoList;";
$query = "SELECT ID,task FROM toDoList;";
$result = $link -> query($query);
if (!$result) die ("Database access failed");
$data = array();
for ($i = 0; $i < $result->num_rows; ++$i) {
//$task = array();
$row = $result->fetch_array(MYSQLI_NUM);
array_push($data, $row[0]);
$data[$row[0]] = $row[1];
}
header('Content-Type: application/json');
echo json_encode($data);
$link->close();
?>
var i = 0;
//var i = 0;
/*
//add new row to list after submitting
function addRow(){
if (document.getElementById('add-task').value!=''){
i++;
var title = document.getElementById('add-task').value;
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>';
document.getElementById('doList').appendChild(node);
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>';
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
function deleteAll() {
......@@ -43,23 +59,46 @@ $("#imageUpload").change(function() {
readURL(this);
});
//display input from database
$(document).ready(function() {
//display input from the database
$.ajax({
dataType: 'JSON',
url: 'display.php',
success: function(data) {
var items = [];
//var items = [];
$.each( data, function(key, val) {
i++;
var title = val;
//i++;
//var title = val
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);
})
}
});
});
/*
//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
$(document).ready(function() {
......@@ -70,7 +109,9 @@ $(document).ready(function() {
$.ajax({
type: "GET",
url: "delete-complete.php",
data: {task: $(this).next().children(".check--label-text").text()}
data: {
id: $(this).next().attr("for")
}
});
$(this).parent().remove();
});
......
......@@ -7,8 +7,16 @@ $("#addAction").submit(function(event) {
type:"POST",
data:{
"task": task },
success: function() {
success: function(data) {
$("#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>
<html lang="en">
<head>
......@@ -29,9 +39,9 @@
<div class="extra-content" id="extraContent">
<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 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>
<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">
</form>
</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";
$query = "INSERT INTO toDoList (task) VALUES (?) ";
$query = $link->prepare($query);
$query -> bind_param('s', $_POST['task']);
$query -> execute();
$query->bind_param('s', $_POST['task']);
$query ->execute();
$last_id = mysqli_insert_id($link);
echo $last_id;
$query -> close();
$link -> close();
?>
......@@ -8,9 +8,9 @@
<div class="row">
<div class="column">
<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>
<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>
<label for="password">Password&nbsp</label>
<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";
* {
box-sizing: border-box;
font-family: 'Roboto Slab', serif;
font-size: 20px;
}
@media print{
#form {
overflow-y:hidden;
}
#side {
display: none; }
#action{
display: none;
}
#addAction{
display: none;
}
#buttonExtra{
display: none;
}
#extraContent{
display: none;
}
#dropContent{
display: none;
}
#doList {
display: block;
position: absolute;
top: 10px;
left: 20px;
}
}
@media screen and (max-width: 600px) {
body {
float: none;
}
}
.row {
margin: 0 -5px;
display: flex;
width: 100%;
min-width: 1050px;
}
.main {
width: 100%;
float:none;
}
.card {
height: 100%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 20px;
text-align: center;
background-color: #f1f1f1;
margin: 10px 10px 10px 10px;
}
.list-card {
height: 35%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 12px;
text-align: center;
font-family: 'Roboto Slab', serif;
background-color: #f1f1f1;
text-align: center;
margin: 10px 10px 10px 10px;
}
.task-card {
cursor: pointer;
width: 220px;
height: 64%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 30px;
margin: 10px 10px 10px 10px;
text-align: center;
background-color: #f1f1f1;
}
.side {
padding: 0px 5px 0px 30px;
}
.extra-content {
font-family: 'Roboto Slab', serif;
width: 100%;
border-radius: 6px;
}
.extra-content a {
color: black;
padding: 15px 16px;
display: block;
border-radius: 6px;
}
.extra-content a:hover {
color: white;
background-color:#b198e6b9;
}
.logout-button {
background-color: #9370DB;
font-family: 'Roboto Slab', serif;
width: 100%;
padding: 10px;
border-radius: 6px;
border: none;
transition: all 0.5s;
cursor: pointer;
display: inline-block;
color: white;
}
.logout-button:hover{
background: red;
}
input[type=text] {
width: 70%;
box-sizing: border-box;
border: 2px solid #9370DB;
border-radius: 6px;
background-color: white;
padding: 12px 0 12px 40px;
float:left;
margin-left: 90px;
margin-top: 60px;
}
.add-button {
background-color:rgb(83, 68, 170);
font-family: 'Roboto Slab', serif;
width: 10%;
color: white;
padding: 14px;
border-radius: 6px;
border: none;
transition: all 0.5s;
cursor: pointer;
float: left;
margin-top: 60px;
margin-left: 5px;
}
.add-button:hover{
background-color: #9370DB;
color: white;
}
.task-board {
border: 6px;
margin-top: 150px;
margin-left: 90px;
width: 80%;
background-color: white;
border-radius: 15px;
overflow-y: scroll;
min-width: 200px;
height: 460px;
}
.checkmark {
position: absolute;
top: 9px;
left: 15px;
height: 25px;
width: 25px;
border-radius: 50%;
background-color: #eee;
}
.hidden {
position: absolute;
appearance: none;
}
.check--label {
display: flex;
justify-content: flex-start;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
margin-top: 15px;
height: 40px;
}
.check--label-box {
display: flex;
align-self: center;
position: relative;
height: 25px;
width: 25px;
margin: 0 20px;
border: 2px solid rgb(83, 68, 170);
cursor: pointer;
border-radius: 50%;
}
.check--label-text {
position: relative;
display: flex;
cursor: pointer;
align-self: center;
padding: 20px;
font-size: 22px;
border-left: 1px solid #ecf0f1;
}
.check--label-text:after {
content: '';
display: block;
width: 0%;
height: 2px;
background-color: #000;
position: absolute;
top: 50%;
left: 7.5%;
transform: translateY(-50%);
transition: width 100ms ease-in-out;
}
.hidden:checked + .check--label {
background-color: #fff;
}
.hidden:checked + .check--label .check--label-box {
background-color: rgb(83, 68, 170);
}
.hidden:checked + .check--label .check--label-box:after {
content: '';
display: block;
position: absolute;
top: 3px;
left: 7px;
width: 7px;
height: 12px;
border: solid white;
border-width: 0 3px 3px 0;
transform: rotate(45deg);
}
.hidden:checked + .check--label .check--label-text:after {
width: 85%;
}
.avatar-upload {
position: relative;
max-width: 205px;
margin: 50px auto;
}
.avatar-edit {
position: absolute;
right: 12px;
z-index: 1;
top: -20px;
}
.avatar-upload .avatar-edit input {
display: none;
}
.avatar-upload input + label {
display: inline-block;
width: 34px;
height: 34px;
margin-bottom: 0;
border-radius: 100%;
background: #FFFFFF;
border: 1px solid transparent;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
cursor: pointer;
font-weight: normal;
transition: all .2s ease-in-out;
}
.avatar-upload input + label:hover {
background: #f1f1f1;
border-color: #d6d6d6;
}
.avatar-upload input + label:after {
content: "\f040";
font-family: 'FontAwesome';
color: #757575;
position: absolute;
top: 2px;
left: 0px;
right: 0px;
text-align: center;
margin: auto;
}
.avatar-preview {
width: 190px;
height: 190px;
position: relative;
top: -35px;
border-radius: 100%;
border: 6px solid #F8F8F8;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
}
.avatar-preview > div {
width: 100%;
height: 100%;
border-radius: 50%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
@charset "UTF-8";
* {
box-sizing: border-box;
font-family: 'Roboto Slab', serif;
font-size: 20px;
}
@media print{
#form {
overflow-y:hidden;
}
#side {
display: none; }
#action{
display: none;
}
#addAction{
display: none;
}
#buttonExtra{
display: none;
}
#extraContent{
display: none;
}
#dropContent{
display: none;
}
#doList {
display: block;
position: absolute;
top: 10px;
left: 20px;
}
}
@media screen and (max-width: 600px) {
body {
float: none;
}
}
.row {
margin: 0 -5px;
display: flex;
width: 100%;
min-width: 1050px;
}
.main {
width: 100%;
float:none;
}
.card {
height: 100%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 20px;
text-align: center;
background-color: #f1f1f1;
margin: 10px 10px 10px 10px;
}
.list-card {
height: 35%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 12px;
text-align: center;
font-family: 'Roboto Slab', serif;
background-color: #f1f1f1;
text-align: center;
margin: 10px 10px 10px 10px;
}
.task-card {
cursor: pointer;
width: 220px;
height: 64%;
box-shadow: 0 4px 8px 0 rgba(0,0,0, 0.2);
padding: 30px;
margin: 10px 10px 10px 10px;
text-align: center;
background-color: #f1f1f1;
}
.side {
padding: 0px 5px 0px 30px;
}
.extra-content {
font-family: 'Roboto Slab', serif;
width: 100%;
border-radius: 6px;
}
.extra-content a {
color: black;
padding: 15px 16px;
display: block;
border-radius: 6px;
}
.extra-content a:hover {
color: white;
background-color:#b198e6b9;
}
.logout-button {
background-color: #9370DB;
font-family: 'Roboto Slab', serif;
width: 100%;
padding: 10px;
border-radius: 6px;
border: none;
transition: all 0.5s;
cursor: pointer;
display: inline-block;
color: white;
}
.logout-button:hover{
background: red;
}
input[type=text] {
width: 70%;
box-sizing: border-box;
border: 2px solid #9370DB;
border-radius: 6px;
background-color: white;
padding: 12px 0 12px 40px;
float:left;
margin-left: 90px;
margin-top: 60px;
}
.add-button {
background-color:rgb(83, 68, 170);
font-family: 'Roboto Slab', serif;
width: 10%;
color: white;
padding: 14px;
border-radius: 6px;
border: none;
transition: all 0.5s;
cursor: pointer;
float: left;
margin-top: 60px;
margin-left: 5px;
}
.add-button:hover{
background-color: #9370DB;
color: white;
}
.task-board {
border: 6px;
margin-top: 150px;
margin-left: 90px;
width: 80%;
background-color: white;
border-radius: 15px;
overflow-y: scroll;
min-width: 200px;
height: 460px;
}
.checkmark {
position: absolute;
top: 9px;
left: 15px;
height: 25px;
width: 25px;
border-radius: 50%;
background-color: #eee;
}
.hidden {
position: absolute;
appearance: none;
}
.list {
display: flex;
}
.check--label {
display: flex;
justify-content: flex-start;
flex-direction: row;
flex-wrap: nowrap;
align-items: center;
margin-top: 15px;
height: 40px;
}
.check--label-box {
display: flex;
align-self: center;
position: relative;
height: 25px;
width: 25px;
margin: 0 20px;
border: 2px solid rgb(83, 68, 170);
cursor: pointer;
border-radius: 50%;
}
.check--label-text {
position: relative;
display: flex;
cursor: pointer;
align-self: center;
padding: 20px;
font-size: 22px;
border-left: 1px solid #ecf0f1;
}
.check--label-text:after {
content: '';
display: block;
width: 0%;
height: 2px;
background-color: #000;
position: absolute;
top: 50%;
left: 7.5%;
transform: translateY(-50%);
transition: width 100ms ease-in-out;
}
.hidden:checked + .check--label {
background-color: #fff;
}
.hidden:checked + .check--label .check--label-box {
background-color: rgb(83, 68, 170);
}
.hidden:checked + .check--label .check--label-box:after {
content: '';
display: block;
position: absolute;
top: 3px;
left: 7px;
width: 7px;
height: 12px;
border: solid white;
border-width: 0 3px 3px 0;
transform: rotate(45deg);
}
.hidden:checked + .check--label .check--label-text:after {
width: 85%;
}
.avatar-upload {
position: relative;
max-width: 205px;
margin: 50px auto;
}
.avatar-edit {
position: absolute;
right: 12px;
z-index: 1;
top: -20px;
}
.avatar-upload .avatar-edit input {
display: none;
}
.avatar-upload input + label {
display: inline-block;
width: 34px;
height: 34px;
margin-bottom: 0;
border-radius: 100%;
background: #FFFFFF;
border: 1px solid transparent;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.12);
cursor: pointer;
font-weight: normal;
transition: all .2s ease-in-out;
}
.avatar-upload input + label:hover {
background: #f1f1f1;
border-color: #d6d6d6;
}
.avatar-upload input + label:after {
content: "\f040";
font-family: 'FontAwesome';
color: #757575;
position: absolute;
top: 2px;
left: 0px;
right: 0px;
text-align: center;
margin: auto;
}
.avatar-preview {
width: 190px;
height: 190px;
position: relative;
top: -35px;
border-radius: 100%;
border: 6px solid #F8F8F8;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
}
.avatar-preview > div {
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