This repository has been archived by the owner on Nov 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathajax.php
100 lines (81 loc) · 2.54 KB
/
ajax.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once dirname(__FILE__).'/includes/common.php';
if(LOGGED_IN == true){
if( isset($_SESSION['user_id']) ){
$username = $_SESSION['user_id'];
}
}
else{
/*header("Location:".."home.php");
exit; */
die ("You are not logged in.");
}
if( initDB() == true ){
if(isset($_POST['remove_event_id'])){
$event_id = $_POST['remove_event_id'];
/*REMOVE the respective event here*/
$query = "DELETE from todo_event where id='".$event_id."'";
$exec = mysql_query($query);
if( !$exec ){
die(mysql_error());
}
}
if( isset($_POST['update_event_id']) ){
$event_id = $_POST['update_event_id'];
/*REMOVE the respective event here*/
$query = "UPDATE todo_event SET status='done' where id='".$event_id."'";
$exec = mysql_query($query);
if( !$exec ){
die(mysql_error());
}
}
if( isset($_POST['e_title']) && isset($_POST['e_desc']) ){
$e_title = $_POST['e_title'];
$e_desc = $_POST['e_desc'];
$user_id = getUserId($_SESSION['user_id']);
$query = sprintf("INSERT INTO todo_event(user_id,title,description,status) VALUES('%d','%s','%s','pending')",
mysql_real_escape_string($user_id),
mysql_real_escape_string($e_title),
mysql_real_escape_string($e_desc));
//$query = "INSERT INTO todo_event(user_name,title,description,status) VALUES('".$_SESSION['user_id']."','".$e_title."','".$e_desc."','pending')";
//die($query);
$exec = mysql_query($query);
if( !$exec ){
die(mysql_error());
}
}
$user_id = getUserId($_SESSION['user_id']);
$query = "SELECT * FROM todo_event WHERE user_id ='".$user_id."' ORDER BY status DESC";
$exec = mysql_query($query);
if( !$exec ){
die (mysql_error());
}
else{
$empty_flag=0;
while($row = mysql_fetch_array($exec)){
$empty_flag=1;
echo "<div class='event ".$row['status']."' id='".$row['id']."' >\n";
echo "<a href='#' class='event_drop' rel='".$row['id']."'>x</a>";
echo "<div class='clear'></div>";
echo "<h2 class='event_title'>".htmlspecialchars($row['title'])."</h2>\n";
echo "<p class='event_description'>".htmlspecialchars($row['description'])."</p>\n";
echo '<p class="options">';
if($row['status'] == "pending"){
echo "<span class='event_status'>Pending</span>\n";
echo "<a href='#' class='event_change_status' rel='".$row['id']."'>Mark as done ✓</a>";
}
else {
echo "<span class='event_status'>Done ✓</span>\n";
}
echo '</p>';
echo "</div>\n";
}
if($empty_flag == 0){
echo "<h2>You don't have any tasks yet.</h2>";
}
}
}
else{
echo "Unknown error occured.<br/>";
}
?>