-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
437 lines (332 loc) · 21.9 KB
/
index.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
<!-- calendar starter code from https://davidwalsh.name/php-calendar -->
<DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> <!-- required to handle IE -->
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<link rel="stylesheet" href="calendar.css?1422585377" type="text/css" />
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src = "bootstrap/js/bootstrap.js"></script>
<title> Time Savvy </title>
</head>
<body style="margin:50 30 30 30">
<div class="container-fluid">
<!-- referenced w3 site to learn how to use bootstrap's modal feature -->
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title" id="exampleModalLongTitle">Preferences</h3>
</div>
<form action="http://localhost:8080/webprj/TimeSavvy" method="get">
<div class="modal-body">
Select what type of motivational messages you would like to receive:
<br>
<input type="radio" name="motivationType" value="gentle"> Gentle <br>
<input type="radio" name="motivationType" value="neutral" checked> Neutral <br>
<input type="radio" name="motivationType" value="aggressive"> Aggressive
<br/>
<br/>
<input type="checkbox" name="notifications" value="none"> None <br/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" class="send btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
<header>
<!-- 4. add navbar (code from getbootstrap.com >> components >> navbar) -->
<!-- try
navbar-static-top
- creates a full-width navbar that scrolls away with the page
- removes the left, right, and top border created by navbar-default
navbar-fixed-top
- creates a full-width navbar that sticks to the page
navbar-inverse sets background to dark color scheme
-->
<!-- <nav class="navbar navbar-inverse navbar-static-top"> -->
<!-- <nav class="navbar navbar-inverse navbar-default"> -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<!-- 5. bootstrap requires a containing element to wrap site contents.
There are two container classes to choose from (based on the above css bootstrap):
(1) .container class provides a responsive fixed width container
(2) .container-fluid class provides a full width container, spanning
the entire width of the view point
Both .container and .container-fluid set a max-width on the content
and cause the center alignment
-->
<div class="container">
<div class="navbar-header">
<!-- 6. The button is hidden on desktop and becomes a dropdown hamburger menu on mobile.
The navigation bar is hidden on small screens and
replaced by a button in the top right corner (try to re-size this window).
Only when the button (hamburger menu) is clicked, the navigation bar will be displayed.
(each <span class="icon-bar"> is a line in the hamburger menu)
-->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.php">Time Savvy <?php if (isset($_POST['motType'])) { echo $_POST['motType']; } ?> </a>
</div>
<!-- 7. nav-collapse makes it possible to expand and collapse the menu
require: javascript plugin (we use js bootstrap here, at the bottom)
commonly, lists with links are used for navigation
-->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login_view.html">Log In</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Social<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Design</a></li>
<li><a href="#">Development</a></li>
<li><a href="#">Consulting</a></li>
</ul>
</li>
<li><a href="#myModal" data-toggle="modal" data-target="#myModal" class="pref">Preferences</a></li>
</div>
</div>
</ul>
</div>
</div>
</nav>
</header>
<div class="row">
<!--<a href="#" id="popover" data-toggle="popover" title="Popover Header" data-content="Tasks">Toggle popover</a> -->
<div class="col-sm-8">
<?php
require 'vendor/autoload.php';
/* draws a calendar */
function draw_calendar($month,$year){
/* draw table */
$calendar = '<table cellpadding="0" cellspacing="0" class="calendar" />';
/* table headings */
$headings = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
$calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';
/* days and weeks vars now ... */
$running_day = date('w',mktime(0,0,0,$month,1,$year));
$days_in_month = date('t',mktime(0,0,0,$month,1,$year));
$days_in_this_week = 1;
$day_counter = 0;
$dates_array = array();
/* row for week one */
$calendar.= '<tr class="calendar-row">';
/* print "blank" days until the first of the current week */
for($x = 0; $x < $running_day; $x++):
$calendar.= '<td class="calendar-day-np"> </td>';
$days_in_this_week++;
endfor;
/* edited code to show what the current day is
- added if/else statement
- added $now variable to get what the current date is
- added id current day to allow for css rules to be added
*/
$now = new Moment\Moment();
if ($now->getMonth() == $month && $now->getYear() == $year){
/* keep going with days.... */
for($list_day = 1; $list_day <= $days_in_month; $list_day++){
if ($list_day == ($now->getDay())){
$date = (string)($now->format('F j, o'));
$day = '<td class="calendar-day" id="current-day" onclick="newPopper(this, \'' . $date . ' \')" />';
$calendar.= $day;
/* add in the day number */
$num = '<div class="day-number" id="current-num">'.$list_day.'</div>';
$calendar.= $num;
$calendar.= str_repeat('<p> </p>',1);
$calendar.= '</td>';
if($running_day == 6):
$calendar.= '</tr>';
if(($day_counter+1) != $days_in_month):
$calendar.= '<tr class="calendar-row">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
}
else{
$date = $list_day . '-' . $month . '-' . $year;
$date = date('F j, o', strtotime($date));
$calendar.= '<td class="calendar-day" onclick="newPopper(this, \'' . $date . ' \')" />';
/* add in the day number */
$calendar.= '<div class="day-number">'.$list_day.'</div>';
$calendar.= str_repeat('<p> </p>',1);
$calendar.= '</td>';
if($running_day == 6):
$calendar.= '</tr>';
if(($day_counter+1) != $days_in_month):
$calendar.= '<tr class="calendar-row">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
}
}
}
else {
for($list_day = 1; $list_day <= $days_in_month; $list_day++){
$date = date('F j, o', strtotime($date));
$calendar.= '<td class="calendar-day" onclick="newPopper(this, \'' . $date . ' \')" />';
/* add in the day number */
$calendar.= '<div class="day-number">'.$list_day.'</div>';
$calendar.= str_repeat('<p> </p>',2);
$calendar.= '</td>';
if($running_day == 6):
$calendar.= '</tr>';
if(($day_counter+1) != $days_in_month):
$calendar.= '<tr class="calendar-row">';
endif;
$running_day = -1;
$days_in_this_week = 0;
endif;
$days_in_this_week++; $running_day++; $day_counter++;
}
}
/* finish the rest of the days in the week */
if($days_in_this_week < 8 && $days_in_this_week !=1):
for($x = 1; $x <= (8 - $days_in_this_week); $x++):
$calendar.= '<td class="calendar-day-np"> </td>';
endfor;
endif;
/* final row */
$calendar.= '</tr>';
/* end the table */
$calendar.= '</table>';
/* all done, return result */
return $calendar;
}
/*-- own code to create calendar based on current month and year*/
$m = new Moment\Moment();
$month = '<span class="month">' . $m->format('F o') . '</span>';
echo $month;
$cal = draw_calendar(($m->getMonth()), ($m->getYear()));
echo $cal;
?>
</div>
<!-- own code based on inclass toDo demo -->
<div class="col-sm-4">
<div class="todo">
<h2 style="font-family:Didot; font-weight:bold;"> Upcoming Events
<button class="btn btn-link btn-m" style="margin-left:20px; margin-top:-8px;"data-toggle="collapse" data-target="#addTask">
<span class="glyphicon glyphicon-plus"></span>
</button>
</h2>
<br/>
<div id="addTask" class="collapse">
<form method="get" action="<?php echo $_SERVER['PHP_SELF'];?>">
<div class="form-group">
<label for="task">Task:</label>
<input style="background:rgba(255,255,255,0.5)" type="text" class="form-control" id="task" placeholder="What do you need to do?">
</div>
<div class="form-group">
<label for="due">Due Date:</label>
<input style="background:rgba(255,255,255,0.5)" type="text" class="form-control" id="due" placeholder="When should it be done?">
</div>
<input type="submit" class="btn btn-submit" onclick="addTask()" style="background:light gray; color:white;"/>
</form>
</div>
<table id="todoTable">
<thead>
<tr>
<th style="width:200; font-weight:bold;">Task</th>
<th style="width:130; font-weight:bold;">Due Date</th>
</tr>
</thead>
</table>
</div>
</div>
<script type="text/javascript">
function Task(t, d, c) {
this.task = t;
this.due = d;
this.complete = c;
}
var tasks = [];
<!-- own code based on in class demo -->
function addTask() {
if (document.getElementById("task").value == "" || document.getElementById("due").value == "") {
window.alert("Please complete all fields to add a task.");
}
else {
var task = document.getElementById("task").value;
var due = document.getElementById("due").value;
var newTask = new Task(task, due, false);
tasks.push(newTask);
tasks.sort(function(a, b){return a.due.getTime() - b.due.getTime()});
console.log(tasks);
var todo = document.getElementById("todoTable");
var newRow = todo.insertRow(todo.rows.length);
newRow.style = "border-top:1px solid black";
var newCell = newRow.insertCell(0);
newCell.innerHTML = task;
newCell = newRow.insertCell(1);
newCell.innerHTML = due;
document.getElementById("task").value = "";
document.getElementById("due").value = "";
sortTable();
}
}
function addTask(t, d) {
var task = t;
var due = d;
var todo = document.getElementById("todoTable");
var newRow = todo.insertRow(todo.rows.length);
newRow.style = "border-top:1px solid black";
var newCell = newRow.insertCell(0);
newCell.innerHTML = task;
newCell = newRow.insertCell(1);
newCell.innerHTML = due;
document.getElementById("task").value = "";
document.getElementById("due").value = "";
sortTable();
}
function newPopper(x, y) {
var task = window.prompt("Add Task for " + y);
if (task) {
var y = new Date(y);
var newTask = new Task(task, y, false);
tasks.push(newTask);
tasks.sort(function(a, b){return a.due.getTime() - b.due.getTime()});
console.log(tasks);
addTask(newTask.task, newTask.due);
x.innerHTML += '• ' + task + '<br/>';
}
}
//sort table code from w3 tutorial
function sortTable() {
var table, rows, switching, i, x, y, shouldSwitch;
table = document.getElementById("todoTable");
rows = table.getElementsByTagName("TR");
for (i = 1; i < (rows.length - 1); i++) {
switching = false;
x = rows[i].getElementsByTagName("TD")[1];
for (n = 1; n < (rows.length - 1); n++) {
shouldSwitch = false;
y = rows[n].getElementsByTagName("TD")[1];
if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
rows[i].parentNode.insertBefore(rows[n], rows[i]);
}
}
}
}
</script>
</div>
</div>
</body>
</html>