-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtodo.class.php
154 lines (129 loc) · 4.61 KB
/
todo.class.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
class todo{
private $db;
protected $title = null;
protected $id = null;
protected $completed = false;
function __construct($DB_con){
$this->db = $DB_con;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @param mixed $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @param boolean $completed
*/
public function setCompleted($completed)
{
$this->completed = $completed;
}
public function add(){
try{
$stmt = $this->db->prepare("INSERT INTO tbltodo(title) VALUES(:title)");
$stmt->bindparam(":title",$this->title);
$stmt->execute();
return true;
}catch(PDOException $e){
echo $e->getMessage();
return false;
}
}
public function get($id)
{
$stmt = $this->db->prepare("SELECT * FROM tbltodo WHERE id=:id");
$stmt->execute(array(":id"=>$id));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
public function remove(){
$stmt = $this->db->prepare("DELETE FROM tbltodo WHERE id=:id");
$stmt->bindparam(":id",$this->id);
$stmt->execute();
return true;
}
function all(){
$stmt = $this->db->prepare("SELECT * FROM tbltodo ORDER BY id DESC ");
$stmt->execute();
if($stmt->rowCount() >0){
while ($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<li>
<h1> <?php print($row['title']); ?> </h1>
<h3> Status :<?php print($row['completed']); ?> </h3>
<form method="post">
<?php
if ($row['completed'] == 1){
echo "<input type='radio' name=rad-{$row['id']} value='1' checked /> Completed task <br/>";
echo "<input type='radio' name=rad-{$row['id']} value='0' /> An incomplete task <br/>";
}
else{
echo "<input type='radio' name=rad-{$row['id']} value='1' /> Completed task <br/>";
echo "<input type='radio' name=rad-{$row['id']} value='0' checked /> An incomplete task <br/>";
echo "<button type='submit' value={$row['id']} class='' name='btn-complete'> Complete </button>";
}
?>
<button type="submit" value= <?php print($row['id']); ?> class="" name="btn-edit"> Edit </button>
<button type="submit" value= <?php print($row['id']); ?> class="" name="btn-delete"> Delete </button>
</form>
</li>
<?php
}
}else {
echo "<h1> There is no list </h1>";
}
}
// *************************************************************************************
// ****** the next function can be used to return the completed and incompleted ********
//**************************************************************************************
public function completed($status)
{
$stmt = $this->db->prepare("SELECT * FROM tbltodo WHERE completed=:completed");
$stmt->execute(array(":completed"=>$status));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
public function active($status)
{
$stmt = $this->db->prepare("SELECT * FROM tbltodo WHERE completed=:completed");
$stmt->execute(array(":completed"=>$status));
$editRow=$stmt->fetch(PDO::FETCH_ASSOC);
return $editRow;
}
public function complete(){
try{
$stmt = $this->db->prepare("UPDATE tbltodo SET completed='1'
WHERE id=:id ");
$stmt->bindparam(":id",$this->id);
$stmt->execute();
return true;
}catch(PDOException $e){
echo $e->getMessage();
return false;
}
}
public function edit(){
try{
$stmt = $this->db->prepare("UPDATE tbltodo SET completed=:completed,
title =:title WHERE id=:id ");
$stmt->bindparam(":id",$this->id);
$stmt->bindparam(":title",$this->title);
$stmt->bindparam(":completed",$this->completed);
$stmt->execute();
return true;
}catch(PDOException $e){
echo $e->getMessage();
return false;
}
}
}