Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
sopham
/
todolist
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
15421a6a
authored
May 11, 2019
by
sopham
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete tasks by id, php user authentication
parent
e476aa2f
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
147 additions
and
29 deletions
authentication.php
dbconnection.php
delete-all.php
delete-complete.php
display.php
function.js
function1.js
index.php
index_php.php
insert.php
login_page.php
logout.php
style.css
authentication.php
0 → 100644
View file @
15421a6a
<?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
();
}
?>
dbconnection.php
View file @
15421a6a
<?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
);
?>
delete-all.php
View file @
15421a6a
<?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
();
?>
delete-complete.php
View file @
15421a6a
<?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
();
...
...
display.php
View file @
15421a6a
...
...
@@ -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
();
?>
function.js
View file @
15421a6a
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>'
;
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
();
});
...
...
function1.js
View file @
15421a6a
...
...
@@ -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
);
}
}
});
});
...
...
index.php
View file @
15421a6a
<?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=
"log
in_check
.php"
method=
"POST"
id=
"action"
>
<form
action=
"log
out
.php"
method=
"POST"
id=
"action"
>
<input
type=
"submit"
class=
"logout-button"
name=
"logout"
value=
"Logout"
>
</form>
</div>
...
...
index_php.php
0 → 100755
View file @
15421a6a
<?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'
);
}
?>
insert.php
View file @
15421a6a
...
...
@@ -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
();
?>
login_page.php
View file @
15421a6a
...
...
@@ -8,7 +8,7 @@
<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
>
<br>
...
...
logout.php
0 → 100644
View file @
15421a6a
<?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"
);
?>
style.css
View file @
15421a6a
@charset
"UTF-8"
;
*
{
...
...
@@ -181,6 +182,10 @@ input[type=text] {
appearance
:
none
;
}
.list
{
display
:
flex
;
}
.check--label
{
display
:
flex
;
justify-content
:
flex-start
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment