This repository was archived by the owner on Mar 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd.php
More file actions
233 lines (223 loc) · 8.81 KB
/
add.php
File metadata and controls
233 lines (223 loc) · 8.81 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
//Chore, Copyright Josh Fradley (http://github.com/joshf/Chore)
if (!file_exists("config.php")) {
die("Error: Config file not found!");
}
require_once("config.php");
session_start();
if (!isset($_SESSION["chore_user"])) {
header("Location: login.php");
exit;
}
//Connect to database
@$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (mysqli_connect_errno()) {
die("Error: Could not connect to database (" . mysqli_connect_error() . "). Check your database settings are correct.");
}
$getusersettings = mysqli_query($con, "SELECT `user` FROM `users` WHERE `id` = \"" . $_SESSION["chore_user"] . "\"");
if (mysqli_num_rows($getusersettings) == 0) {
session_destroy();
header("Location: login.php");
exit;
}
$resultgetusersettings = mysqli_fetch_assoc($getusersettings);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<link rel="icon" href="assets/favicon.ico">
<title>Chore » Add</title>
<link rel="apple-touch-icon" href="assets/icon.png">
<link rel="stylesheet" href="assets/bower_components/bootstrap/dist/css/bootstrap.min.css" type="text/css" media="screen">
<link rel="stylesheet" href="assets/css/chore.css" type="text/css" media="screen">
<link rel="stylesheet" href="assets/bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css" type="text/css" media="screen">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<h1>Chore</h1>
<ol class="breadcrumb">
<li><a href="index.php">Chore</a></li>
<li class="active">Add</li>
<li class="pull-right"><span id="add" title="Add" class="glyphicon glyphicon-plus" aria-hidden="true"></span> <span id="settings" title="Settings" class="glyphicon glyphicon-cog" aria-hidden="true"></span> <span id="logout" title="Logout" class="glyphicon glyphicon-log-out" aria-hidden="true"></span></li>
</ol>
<form id="add_form" autocomplete="off">
<div class="form-group">
<label class="control-label" for="item">Item</label>
<input type="text" class="form-control" id="item" name="item" placeholder="Type a item..." required>
</div>
<div class="form-group">
<label class="control-label" for="details">Details</label>
<textarea class="form-control" id="details" name="details" placeholder="Type any extra details..."></textarea>
</div>
<div id="new_category_holder" class="hidden">
<div class="form-group">
<label class="control-label" for="new_category">New Category</label>
<input type="text" class="form-control" id="new_category" name="new_category" placeholder="Type a new category..." required disabled>
</div>
</div>
<div id="category_holder">
<div class="form-group">
<label class="control-label" for="category">Category</label>
<div class="input-group">
<select class="form-control" id="category" name="category">
<?php
//Don"t duplicate none entry
$doesnoneexist = mysqli_query($con, "SELECT `category` FROM `categories` WHERE `category` = \"none\"");
if (mysqli_num_rows($doesnoneexist) == 0) {
echo "<option value=\"\">None</option>";
}
//Get categories
$getcategories = mysqli_query($con, "SELECT `id`, `category` FROM `categories`");
while($category = mysqli_fetch_assoc($getcategories)) {
echo "<option value=\"" . $category["id"] . "\">" . ucfirst($category["category"]) . "</option>";
}
?>
</select>
<span id="add_category" class="input-group-addon">
<i class="glyphicon glyphicon-plus"></i>
</span>
</div>
</div>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="has_due" name="has_due"> <span id="has_due_message">Due date required</span>
</label>
</div>
<div class="form-group">
<input type="date" class="due form-control" id="due" name="due" disabled>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="priority" name="priority"> High Priority
</label>
</div>
<input type="hidden" id="action" name="action" value="add">
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-plus-sign" title="Add" aria-hidden="true"></span> Add</button>
</form>
</div>
<script src="assets/bower_components/jquery/dist/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/bower_components/bootstrap/dist/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/bower_components/modernizr-load/modernizr.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/bower_components/bootstrap-validator/dist/validator.min.js" type="text/javascript" charset="utf-8"></script>
<script src="assets/bower_components/remarkable-bootstrap-notify/dist/bootstrap-notify.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#has_due").click(function() {
if ($(this).is(":checked")) {
$("#due").prop("disabled", false);
$("#due").prop("required", true);
} else {
$("#due").prop("disabled", true);
$("#due").prop("required", false);
}
});
$("#new_category").on("keydown", function(e) {
if (e.which == 13) {
var new_category = $("#new_category").val();
if (new_category !== null && new_category != "") {
$.ajax({
type: "POST",
url: "worker.php",
data: "action=addcategory&new_category="+ new_category +"",
dataType: "json",
error: function() {
$.notify({
message: "Ajax query failed!",
icon: "glyphicon glyphicon-warning-sign",
},{
type: "danger",
allow_dismiss: true
});
},
success: function(resp) {
$("#new_category").prop("disabled", true);
$("#category").append("<option value=\"" + resp.category[0].id + "\" selected=\"selected\">" + new_category + "</option>");
$("#new_category_holder").addClass("hidden");
$("#category_holder").removeClass("hidden");
}
});
event.preventDefault();
}
}
});
$("#add_category").click(function() {
$("#new_category_holder").removeClass("hidden");
$("#new_category").prop("disabled", false);
$("#new_category").focus();
$("#category_holder").addClass("hidden");
});
if (!Modernizr.inputtypes.date) {
$(".due").datepicker({
format: "dd-mm-yyyy",
autoclose: "true",
todayHighlight: "true"
});
}
$("#add_form").validator({
disable: true
});
$("#add_form").on("validate.bs.validator", function (e) {
if ($("#due").parent().hasClass("has-error")) {
$("#has_due_message").addClass("text-danger");
} else {
$("#has_due_message").removeClass("text-danger");
}
});
$("#add_form").on("valid.bs.validator", function (e) {
$("#due").parent().removeClass("has-error");
$("#has_due_message").removeClass("text-danger");
});
$("#add_form").validator().on("submit", function (e) {
if (e.isDefaultPrevented()) {
return false;
}
$.ajax({
type: "POST",
url: "worker.php",
data: $("#add_form").serialize(),
error: function() {
$.notify({
message: "Ajax query failed!",
icon: "glyphicon glyphicon-warning-sign",
},{
type: "danger",
allow_dismiss: true
});
},
success: function() {
$.notify({
message: "Item added!",
icon: "glyphicon glyphicon-ok",
},{
type: "success",
allow_dismiss: true
});
$("#category").val("");
$("#add_form").trigger("reset");
}
});
return false;
});
$("#add").click(function() {
window.location.href = "add.php";
});
$("#settings").click(function() {
window.location.href = "settings.php";
});
$("#logout").click(function() {
window.location.href = "logout.php";
});
});
</script>
</body>
</html>