Review afwezigheidskalender
Ik heb een afwezigheidskalender voor onze club gemaakt. Alles werkt zoals ik verwacht.
concept:
* Enkel dinsdagen
* 6*8 (48) weken
* Start eerste dinsdag van september
De leden kunnen inloggen en hun afwezigheden invullen
De beheerders kunnen alle gegevens aanpassen(afwezigheden en meldingen)
Mijn vraag voor reviewers :) is het veilig en wat kan ik nog verbeteren voor de veiligheid.
Ik weet dat er styles aanwezig zijn in het PHP bestand. dit is om minder te moeten wisselen van bestand. dat komt later in orde.
De functie opendatabasei() is gewoon inloggen op de database en een link terug geven.
De code is compleet (denk ik) op bovenvernoemde functie na.
Code (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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<?php
setlocale(LC_TIME, 'NL_be');
session_name("afwezig");
session_start();
$logedIn=false;
$adminLevel=0;
$un='';
if(isset($_SESSION['myusername']))
{
$un=$_SESSION['myusername'];
setcookie ( "Naam" , $_SESSION['myusername'],mktime(18, 30, 0, 5, 12, 2020 ),"/");
$logedIn=true;
}
include ('../php/define.php');
include ('../php/functions.php');
require_once('../php/PHPMailer/class.phpmailer.php');
$con = opendatabasei();
function fout($msg){
echo '<div class="error">' . $msg . '</div>';
}
function sendMail($wie, $datum){
$pos = strpos ($_SERVER['SERVER_NAME'], ".local/");//geen mail op local test systeem
if ($pos === false){
return;
}
//------------------------------------------//
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = false;
$mail->Host = "beep.beep.beep";
$mail->Port = "25";
$mail->SMTPSecure = "";
$mail->Username = '[email protected]'; // SMTP account username
$mail->Password = 'beeeeeeeeeeeep'; // SMTP account password
$mail->SMTPDebug = 0;
// 1 = errors and messages
// 2 = messages only
//---------------------------------------------------
$sql = '
SELECT
voornaam,
achternaam,
email,
functie
FROM
`post_leden`
JOIN
post_emails ON post_leden.id = post_emails.id
WHERE
admin >0';
$con = opendatabasei();
$result=mysqli_query($con, $sql);
if ($result){
while(list($vnaam, $anaam, $email, $functie)= mysqli_fetch_row($result)){
$mail->AddAddress($email, $functie);
}
$MessageBody = 'Toernooileider,<br><br>';
$MessageBody .= $_SESSION['myusername'] . ' laat weten dat ' . $wie . ' niet kan komen op ' . $datum . '<br><br>';
$MessageBody .= 'De website<br>PS: Gelieve niet te antwoorden op dit automatisch bericht.<br><br><br><br>';
$MessageBody .= '<b>info</b> IP: ' .$_SERVER['REMOTE_ADDR'] . "\n<br>";
$MessageBody .= 'Adres: ' . $_SERVER['SERVER_NAME'] . '/' . $_SERVER['REQUEST_URI'] . "\n";
$mail->MsgHTML($MessageBody);
$mail->SetFrom(admin_email, clubNaam);
$mail->AddReplyTo(admin_email, clubNaam);
$mail->Subject = clubNaam .' Afwezigheid ' . $wie;
$mail->Send();
}
}
if (date("j")<8){
$date = mktime(0, 0, 0, 8, 31, date('Y')-1);
}else{
$date = mktime(0, 0, 0, 8, 31, date('Y'));
}
while (date('N', $date)<>2){
$date = $date + 1;
}
?>
<!doctype html>
<html lang="nl-be">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta NAME="author" content="JanR.be">
<title>
Afwezigheidskalender <?php echo date('Y', $date) . '-' . (date('Y', $date) + 1); ?>
</title>
<style>
label {
display:block;
float:left;
width:300px;
}
td.datum{
width:200px;
font-weight: bold;
border-bottom-style: none ;
font-size: 200%;
}
td.naam{
border-top-style: none ;
height:50px;
color: blue;
}
hr {
height: 6px;
background-color: red;
border: 2px;
}
div.error{
font-size: 200%;
color: red;
font-weight: bold;
}
ul.kies {
width:100%;
background-color: #ff9933;
font-weight: bold;
text-align: left;
}
li.kies {
float: left;
width: 400px;
list-style: none;
}
li.clear {
clear: both;
float: none;
}
ul.kies li.kies:hover a{
color:yellow;
background-color:red;
width:180px;
}
</style>
<link rel="stylesheet" type="text/css" id="css_style" href="style.css">
<link rel="stylesheet" type="text/css" media="print" id="css_printstyle" href="printstyle.css">
<script type="text/javascript" src="menu.php"></script>
<script>
function verwijder(nr){
back=readFile('verwijder.php?id=' + nr);
if (!back==''){
alert(back);
return false;
}else{
reloadlater();
}
}
function komtToch(nr){
back=readFile('komttoch.php?id=' + nr);
if (!back==''){
alert(back);
return false;
}else{
reloadlater();
}
}
function reloadlater(){
setTimeout(function() {window.location=window.location;},1000);
}
function readFile(url) {
pageRequest = new XMLHttpRequest();
pageRequest.open('GET', url, false);
pageRequest.send(null);
return pageRequest.responseText;
}
</script>
</head>
<body>
<form id='login' action="AfwezigheidsKalender.php" method="post" class="hide">
<br><br><br><br><br>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(isset($_POST['myusername'], $_POST['mypassword'])){
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysqli_real_escape_string($con, $myusername);
$mypassword = mysqli_real_escape_string($con, $mypassword);
$sql="SELECT post_leden.ID, post_leden.admin FROM post_emails INNER JOIN post_leden ON post_emails.ID = post_leden.ID WHERE ((post_emails.email='$myusername') and (password='".hash("sha512",$mypassword)."'))";
// echo $sql . "<br>";
$result=mysqli_query($con, $sql);
if ($result){
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
}else{
$count=0;
}
if($count==1){
$_SESSION['myusername']=$myusername;
echo "<a href='AfwezigheidsKalender.php'>Ga verder</a>";
echo "<script type=\"text/javascript\">window.location.href='AfwezigheidsKalender.php';</script>";// opnieuw laden
list($id, $admin)= mysqli_fetch_row( $result);
$_SESSION['id']=$id;
$_SESSION['admin']=$admin;
}else{
echo 'Foutieve inlog gegevens!<br>';
}
}elseif (isset($_POST['afwezig'], $_POST['id'])){
if (is_numeric($_POST['id'])){
$id = $_POST['id'];
$afwezig=$_POST['afwezig'];
if ($afwezig!=''){
$afwezig = stripslashes($afwezig);
$afwezig = mysqli_real_escape_string($con, $afwezig);
str_replace('-','/',$afwezig);
str_replace(' ','/',$afwezig);
str_replace('.','/',$afwezig);
str_replace('\\','/',$afwezig);
$afwezig=explode("/", $afwezig);
if (checkdate($afwezig[1],$afwezig[0],$afwezig[2])){
$a=mktime(0, 0, 0, $afwezig[1],$afwezig[0],$afwezig[2]);
if ( date("w", $a)==2){
if (isset($_POST['opmerking'])){
$opmerking=$_POST['opmerking'];
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}else{
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}
$sql='CREATE TABLE IF NOT EXISTS afwezig (
ID int(11) NOT NULL AUTO_INCREMENT,
NaamID int(11) NOT NULL ,
Datum date NOT NULL,
Afwezig boolean NOT NULL,
opmerking varchar(50) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (ID),
UNIQUE KEY NaamID (Datum, NaamID)
) ENGINE=MyISAM DEFAULT CHARSET=armscii8;';
$result=mysqli_query($con, $sql);
$afwezig=date("Ymd", $a);
//$sql='INSERT INTO `messages` (`Datum` , `message`) VALUES ( '. $msgDate .', "' . $msgText . '") ';
$sql='INSERT INTO `afwezig` ( `NaamID` , `Datum` , `Afwezig` , `opmerking`) VALUES (' . $id . ', '. $afwezig .', TRUE, "' . $opmerking . '") ';
mysqli_query($con, $sql);
$sql = 'select voornaam, achternaam from post_leden where id=' . $id;
$result=mysqli_query($con, $sql);
if ($result){
$d = date("l F Y", $a);
$d = strftime('%A %e %B %G', $a);
/*
A = dag voluit
e = dag vd maand
B = maand voluit
G = jaar 4 cijfers
*/
list($vnaam, $anaam)= mysqli_fetch_row($result);
sendMail($vnaam .' ' . $anaam, $d);
}
}else{
fout('Dit is geen dinsdag!');
}
}else{
fout( 'Dit is geen correcte datum!');
}
}else{
fout( 'Geen datum opgegeven!');
}
}else{
fout( 'Fout in de ingaven!');
}
}elseif (isset($_POST['msgDate'],$_POST['msgText'])){
if ($_POST['msgDate']!=''){
$msgDate=$_POST['msgDate'];
$msgText=$_POST['msgText'];
if ($msgDate!='' && $msgText !=''){
$msgText = stripslashes($msgText);
$msgText = mysqli_real_escape_string($con, $msgText);
if (isset($_POST['msgOpmerking'])){
$opmerking=$_POST['msgOpmerking'];
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}else{
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}
$msgDate = stripslashes($msgDate);
$msgDate = mysqli_real_escape_string($con, $msgDate);
str_replace('-','/',$msgDate);
str_replace(' ','/',$msgDate);
str_replace('.','/',$msgDate);
str_replace('\\','/',$msgDate);
$msgDate=explode("/", $msgDate . '////');
if (is_numeric($msgDate[1]) && is_numeric($msgDate[0]) && is_numeric($msgDate[2])){
if (checkdate($msgDate[1],$msgDate[0],$msgDate[2])){
$a=mktime(0, 0, 0, $msgDate[1],$msgDate[0],$msgDate[2]);
if ( date("w", $a)==2){
$msgDate=date("Ymd", $a);
$sql='CREATE TABLE IF NOT EXISTS messages (
ID int(11) NOT NULL AUTO_INCREMENT,
Datum date NOT NULL,
message varchar(50) COLLATE utf8_bin NOT NULL,
opmerking varchar(50) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (ID),
UNIQUE KEY NaamID (Datum, message)
) ENGINE=MyISAM DEFAULT CHARSET=armscii8;';
$result=mysqli_query($con, $sql);
$sql='INSERT INTO `messages` (`Datum` , `message`, `opmerking`) VALUES ( '. $msgDate .', "' . $msgText . '", "' . $opmerking . '") ';
//echo $sql;
mysqli_query($con, $sql);
}else{
fout('Dit is geen dinsdag!');
}
}else{
fout( 'Dit is geen correcte datum!');
}
}else{
fout( 'Dit is geen datum!');
}
}else{
fout( 'Geen datum of tekst opgegeven!');
}
}else{
fout( 'Fout in de ingaven!');
}
}
}
if($logedIn){
echo 'Ingelogd als: ' . $un;
echo '<input type="button" value="uitloggen" onClick="location.href=\'logout.php\'">';
echo '<br>';
echo '<select id="id" name="id" title="Kies de afwezige speler.">';
$sql='select id,voornaam,achternaam from post_leden where actief=true order by voornaam,achternaam';
$result=mysqli_query($con, $sql);
if ($result){
while(list($id, $vnaam, $anaam)= mysqli_fetch_row($result)){
echo '<option ';
if ($id==$_SESSION['id']){
echo ' selected ';
}
if ($id!=$_SESSION['id'] && $_SESSION['admin']<=0){
echo ' disabled ';
}
echo 'value="'. $id .'">' . $vnaam . ' ' . $anaam . '</option>';
}
}
echo '</select> is afwezig op: ';
echo '<input name="afwezig" type="date" id="afwezig" title="Vul hier de datum in. formaat dd/mm/jjjj">
<input title="De opmerking mag max. 50 karakters zijn. Deze verschijnt als je met de muis boven de getoonde tekst zweeft." type="text" name="opmerking" id="opmerking">
<input name="submit" type="submit" id="submit" value="Verstuur">
</form><br>';
if ($_SESSION['admin']!=0){
echo '<form id="msg" action="AfwezigheidsKalender.php" method="post" class="hide">
Melding voor
<input name="msgDate" type="date" id="msgDate" title="Vul hier de datum in. formaat dd/mm/jjjj">
<input title="De Tekst mag max. 50 karakters zijn." type="text" name="msgText" id="msgText">
<input title="De opmerking mag max. 50 karakters zijn. Deze verschijnt als je met de muis boven de getoonde tekst zweeft." type="text" name="msgOpmerking" id="msgOpmerking">
<input name="submit" type="submit" id="submit2" value="Verstuur">
</form>';
}
}else{
echo 'login:<input name="myusername" type="text" id="myusername">Paswoord:<input name="mypassword" type="password" id="mypassword"> <input type="submit" value="Log in"></form>';
}
$sql='
SELECT afwezig.id,
post_leden.id,
voornaam,
achternaam,
DATE_FORMAT(datum, "%d/%m/%Y") as datum
FROM afwezig
INNER JOIN
post_leden on post_leden.ID = afwezig.naamid';
if (!isset($_SESSION['admin']) || $_SESSION['admin']==0){//niet ingelogd of geen admin
if (isset($_SESSION['admin'])){
$id=$_SESSION['id'];
}else{
$id=-1;
}
$sql .=' where post_leden.id=' . $id . 'and datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
}else{//wel admin dus ook de meldigen beheren
$sql .=' where datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
$sqlMSG='select id, DATE_FORMAT(datum, "%d-%m-%Y"), message from messages';
$sqlMSG .=' where datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
$sqlMSG .=' order by datum, message';
$resultMSG = mysqli_query($con, $sqlMSG);
if ($resultMSG){
echo '<ul class="kies hide">';
while(list($id, $datum, $msg)= mysqli_fetch_row($resultMSG)){
echo '<li class="kies"><input type="button" value="Verwijder" onClick="verwijder(' . $id . ')">' . ' ' . $msg . ' (' . $datum . ')</li>';
}
echo '<li class="clear kies"></li></ul>';
}
}
$sql .=' order by datum, achternaam, voornaam';
$result=mysqli_query($con, $sql);
if ($result){
echo '<ul class="kies hide">';
while(list($afwezigID, $id, $vnaam, $anaam, $datum)= mysqli_fetch_row($result)){
echo '<li class="kies"><input type="button" value="Ik kom toch" onClick="komtToch(' . $afwezigID . ')">' . ' ' . $vnaam . ' ' . $anaam . ' (' . $datum . ')</li>';
}
echo '<li class="clear kies"></li></ul>';
}
?>
<br><br>
<hr>
<table>
<?php
for ($j = 1; $j < 9; $j++) {
echo '<tr>';
$rij2='<tr>';
for ($i = 1; $i <= 6; $i++) {
$rij2.='<td class="naam">';
echo '<td class="datum">'. date('d/m/Y',$date) .'</td>';
$sql='select message,opmerking
FROM messages where datum='.date('Ymd',$date);
$result=mysqli_query($con, $sql);
if ($result){
while(list($msg, $MSGopmerking)= mysqli_fetch_row($result)){
$rij2.= '<div style="color:red;"';
if ($MSGopmerking !=''){
$rij2.= ' title="'.$MSGopmerking.'"';
}
$rij2.= '>' . $msg . '</div>';
}
}
$sql='select voornaam, achternaam, opmerking
FROM afwezig
INNER JOIN post_leden
on post_leden.ID = afwezig.naamid where datum='.date('Ymd',$date).' order by achternaam, voornaam';
//echo $sql .'<br>';
$result=mysqli_query($con, $sql);
if ($result){
while(list($vnaam, $anaam, $opmerking)= mysqli_fetch_row($result)){
$rij2.= '<div';
if ($opmerking !=''){
$rij2.= ' title="'.$opmerking.'"';
}
$rij2.= '>' . $vnaam. ' ' . $anaam . '</div>';
}
}
$rij2.='</td>';
$date = strtotime("+7 day", $date);
}
echo $rij2 . '</tr>';
}
?>
</table>
</body>
</html>
<?php
mysqli_close($con);
?>
setlocale(LC_TIME, 'NL_be');
session_name("afwezig");
session_start();
$logedIn=false;
$adminLevel=0;
$un='';
if(isset($_SESSION['myusername']))
{
$un=$_SESSION['myusername'];
setcookie ( "Naam" , $_SESSION['myusername'],mktime(18, 30, 0, 5, 12, 2020 ),"/");
$logedIn=true;
}
include ('../php/define.php');
include ('../php/functions.php');
require_once('../php/PHPMailer/class.phpmailer.php');
$con = opendatabasei();
function fout($msg){
echo '<div class="error">' . $msg . '</div>';
}
function sendMail($wie, $datum){
$pos = strpos ($_SERVER['SERVER_NAME'], ".local/");//geen mail op local test systeem
if ($pos === false){
return;
}
//------------------------------------------//
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = false;
$mail->Host = "beep.beep.beep";
$mail->Port = "25";
$mail->SMTPSecure = "";
$mail->Username = '[email protected]'; // SMTP account username
$mail->Password = 'beeeeeeeeeeeep'; // SMTP account password
$mail->SMTPDebug = 0;
// 1 = errors and messages
// 2 = messages only
//---------------------------------------------------
$sql = '
SELECT
voornaam,
achternaam,
email,
functie
FROM
`post_leden`
JOIN
post_emails ON post_leden.id = post_emails.id
WHERE
admin >0';
$con = opendatabasei();
$result=mysqli_query($con, $sql);
if ($result){
while(list($vnaam, $anaam, $email, $functie)= mysqli_fetch_row($result)){
$mail->AddAddress($email, $functie);
}
$MessageBody = 'Toernooileider,<br><br>';
$MessageBody .= $_SESSION['myusername'] . ' laat weten dat ' . $wie . ' niet kan komen op ' . $datum . '<br><br>';
$MessageBody .= 'De website<br>PS: Gelieve niet te antwoorden op dit automatisch bericht.<br><br><br><br>';
$MessageBody .= '<b>info</b> IP: ' .$_SERVER['REMOTE_ADDR'] . "\n<br>";
$MessageBody .= 'Adres: ' . $_SERVER['SERVER_NAME'] . '/' . $_SERVER['REQUEST_URI'] . "\n";
$mail->MsgHTML($MessageBody);
$mail->SetFrom(admin_email, clubNaam);
$mail->AddReplyTo(admin_email, clubNaam);
$mail->Subject = clubNaam .' Afwezigheid ' . $wie;
$mail->Send();
}
}
if (date("j")<8){
$date = mktime(0, 0, 0, 8, 31, date('Y')-1);
}else{
$date = mktime(0, 0, 0, 8, 31, date('Y'));
}
while (date('N', $date)<>2){
$date = $date + 1;
}
?>
<!doctype html>
<html lang="nl-be">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta NAME="author" content="JanR.be">
<title>
Afwezigheidskalender <?php echo date('Y', $date) . '-' . (date('Y', $date) + 1); ?>
</title>
<style>
label {
display:block;
float:left;
width:300px;
}
td.datum{
width:200px;
font-weight: bold;
border-bottom-style: none ;
font-size: 200%;
}
td.naam{
border-top-style: none ;
height:50px;
color: blue;
}
hr {
height: 6px;
background-color: red;
border: 2px;
}
div.error{
font-size: 200%;
color: red;
font-weight: bold;
}
ul.kies {
width:100%;
background-color: #ff9933;
font-weight: bold;
text-align: left;
}
li.kies {
float: left;
width: 400px;
list-style: none;
}
li.clear {
clear: both;
float: none;
}
ul.kies li.kies:hover a{
color:yellow;
background-color:red;
width:180px;
}
</style>
<link rel="stylesheet" type="text/css" id="css_style" href="style.css">
<link rel="stylesheet" type="text/css" media="print" id="css_printstyle" href="printstyle.css">
<script type="text/javascript" src="menu.php"></script>
<script>
function verwijder(nr){
back=readFile('verwijder.php?id=' + nr);
if (!back==''){
alert(back);
return false;
}else{
reloadlater();
}
}
function komtToch(nr){
back=readFile('komttoch.php?id=' + nr);
if (!back==''){
alert(back);
return false;
}else{
reloadlater();
}
}
function reloadlater(){
setTimeout(function() {window.location=window.location;},1000);
}
function readFile(url) {
pageRequest = new XMLHttpRequest();
pageRequest.open('GET', url, false);
pageRequest.send(null);
return pageRequest.responseText;
}
</script>
</head>
<body>
<form id='login' action="AfwezigheidsKalender.php" method="post" class="hide">
<br><br><br><br><br>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(isset($_POST['myusername'], $_POST['mypassword'])){
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysqli_real_escape_string($con, $myusername);
$mypassword = mysqli_real_escape_string($con, $mypassword);
$sql="SELECT post_leden.ID, post_leden.admin FROM post_emails INNER JOIN post_leden ON post_emails.ID = post_leden.ID WHERE ((post_emails.email='$myusername') and (password='".hash("sha512",$mypassword)."'))";
// echo $sql . "<br>";
$result=mysqli_query($con, $sql);
if ($result){
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
}else{
$count=0;
}
if($count==1){
$_SESSION['myusername']=$myusername;
echo "<a href='AfwezigheidsKalender.php'>Ga verder</a>";
echo "<script type=\"text/javascript\">window.location.href='AfwezigheidsKalender.php';</script>";// opnieuw laden
list($id, $admin)= mysqli_fetch_row( $result);
$_SESSION['id']=$id;
$_SESSION['admin']=$admin;
}else{
echo 'Foutieve inlog gegevens!<br>';
}
}elseif (isset($_POST['afwezig'], $_POST['id'])){
if (is_numeric($_POST['id'])){
$id = $_POST['id'];
$afwezig=$_POST['afwezig'];
if ($afwezig!=''){
$afwezig = stripslashes($afwezig);
$afwezig = mysqli_real_escape_string($con, $afwezig);
str_replace('-','/',$afwezig);
str_replace(' ','/',$afwezig);
str_replace('.','/',$afwezig);
str_replace('\\','/',$afwezig);
$afwezig=explode("/", $afwezig);
if (checkdate($afwezig[1],$afwezig[0],$afwezig[2])){
$a=mktime(0, 0, 0, $afwezig[1],$afwezig[0],$afwezig[2]);
if ( date("w", $a)==2){
if (isset($_POST['opmerking'])){
$opmerking=$_POST['opmerking'];
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}else{
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}
$sql='CREATE TABLE IF NOT EXISTS afwezig (
ID int(11) NOT NULL AUTO_INCREMENT,
NaamID int(11) NOT NULL ,
Datum date NOT NULL,
Afwezig boolean NOT NULL,
opmerking varchar(50) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (ID),
UNIQUE KEY NaamID (Datum, NaamID)
) ENGINE=MyISAM DEFAULT CHARSET=armscii8;';
$result=mysqli_query($con, $sql);
$afwezig=date("Ymd", $a);
//$sql='INSERT INTO `messages` (`Datum` , `message`) VALUES ( '. $msgDate .', "' . $msgText . '") ';
$sql='INSERT INTO `afwezig` ( `NaamID` , `Datum` , `Afwezig` , `opmerking`) VALUES (' . $id . ', '. $afwezig .', TRUE, "' . $opmerking . '") ';
mysqli_query($con, $sql);
$sql = 'select voornaam, achternaam from post_leden where id=' . $id;
$result=mysqli_query($con, $sql);
if ($result){
$d = date("l F Y", $a);
$d = strftime('%A %e %B %G', $a);
/*
A = dag voluit
e = dag vd maand
B = maand voluit
G = jaar 4 cijfers
*/
list($vnaam, $anaam)= mysqli_fetch_row($result);
sendMail($vnaam .' ' . $anaam, $d);
}
}else{
fout('Dit is geen dinsdag!');
}
}else{
fout( 'Dit is geen correcte datum!');
}
}else{
fout( 'Geen datum opgegeven!');
}
}else{
fout( 'Fout in de ingaven!');
}
}elseif (isset($_POST['msgDate'],$_POST['msgText'])){
if ($_POST['msgDate']!=''){
$msgDate=$_POST['msgDate'];
$msgText=$_POST['msgText'];
if ($msgDate!='' && $msgText !=''){
$msgText = stripslashes($msgText);
$msgText = mysqli_real_escape_string($con, $msgText);
if (isset($_POST['msgOpmerking'])){
$opmerking=$_POST['msgOpmerking'];
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}else{
$opmerking = stripslashes($opmerking);
$opmerking = mysqli_real_escape_string($con, $opmerking);
}
$msgDate = stripslashes($msgDate);
$msgDate = mysqli_real_escape_string($con, $msgDate);
str_replace('-','/',$msgDate);
str_replace(' ','/',$msgDate);
str_replace('.','/',$msgDate);
str_replace('\\','/',$msgDate);
$msgDate=explode("/", $msgDate . '////');
if (is_numeric($msgDate[1]) && is_numeric($msgDate[0]) && is_numeric($msgDate[2])){
if (checkdate($msgDate[1],$msgDate[0],$msgDate[2])){
$a=mktime(0, 0, 0, $msgDate[1],$msgDate[0],$msgDate[2]);
if ( date("w", $a)==2){
$msgDate=date("Ymd", $a);
$sql='CREATE TABLE IF NOT EXISTS messages (
ID int(11) NOT NULL AUTO_INCREMENT,
Datum date NOT NULL,
message varchar(50) COLLATE utf8_bin NOT NULL,
opmerking varchar(50) COLLATE utf8_bin NOT NULL,
PRIMARY KEY (ID),
UNIQUE KEY NaamID (Datum, message)
) ENGINE=MyISAM DEFAULT CHARSET=armscii8;';
$result=mysqli_query($con, $sql);
$sql='INSERT INTO `messages` (`Datum` , `message`, `opmerking`) VALUES ( '. $msgDate .', "' . $msgText . '", "' . $opmerking . '") ';
//echo $sql;
mysqli_query($con, $sql);
}else{
fout('Dit is geen dinsdag!');
}
}else{
fout( 'Dit is geen correcte datum!');
}
}else{
fout( 'Dit is geen datum!');
}
}else{
fout( 'Geen datum of tekst opgegeven!');
}
}else{
fout( 'Fout in de ingaven!');
}
}
}
if($logedIn){
echo 'Ingelogd als: ' . $un;
echo '<input type="button" value="uitloggen" onClick="location.href=\'logout.php\'">';
echo '<br>';
echo '<select id="id" name="id" title="Kies de afwezige speler.">';
$sql='select id,voornaam,achternaam from post_leden where actief=true order by voornaam,achternaam';
$result=mysqli_query($con, $sql);
if ($result){
while(list($id, $vnaam, $anaam)= mysqli_fetch_row($result)){
echo '<option ';
if ($id==$_SESSION['id']){
echo ' selected ';
}
if ($id!=$_SESSION['id'] && $_SESSION['admin']<=0){
echo ' disabled ';
}
echo 'value="'. $id .'">' . $vnaam . ' ' . $anaam . '</option>';
}
}
echo '</select> is afwezig op: ';
echo '<input name="afwezig" type="date" id="afwezig" title="Vul hier de datum in. formaat dd/mm/jjjj">
<input title="De opmerking mag max. 50 karakters zijn. Deze verschijnt als je met de muis boven de getoonde tekst zweeft." type="text" name="opmerking" id="opmerking">
<input name="submit" type="submit" id="submit" value="Verstuur">
</form><br>';
if ($_SESSION['admin']!=0){
echo '<form id="msg" action="AfwezigheidsKalender.php" method="post" class="hide">
Melding voor
<input name="msgDate" type="date" id="msgDate" title="Vul hier de datum in. formaat dd/mm/jjjj">
<input title="De Tekst mag max. 50 karakters zijn." type="text" name="msgText" id="msgText">
<input title="De opmerking mag max. 50 karakters zijn. Deze verschijnt als je met de muis boven de getoonde tekst zweeft." type="text" name="msgOpmerking" id="msgOpmerking">
<input name="submit" type="submit" id="submit2" value="Verstuur">
</form>';
}
}else{
echo 'login:<input name="myusername" type="text" id="myusername">Paswoord:<input name="mypassword" type="password" id="mypassword"> <input type="submit" value="Log in"></form>';
}
$sql='
SELECT afwezig.id,
post_leden.id,
voornaam,
achternaam,
DATE_FORMAT(datum, "%d/%m/%Y") as datum
FROM afwezig
INNER JOIN
post_leden on post_leden.ID = afwezig.naamid';
if (!isset($_SESSION['admin']) || $_SESSION['admin']==0){//niet ingelogd of geen admin
if (isset($_SESSION['admin'])){
$id=$_SESSION['id'];
}else{
$id=-1;
}
$sql .=' where post_leden.id=' . $id . 'and datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
}else{//wel admin dus ook de meldigen beheren
$sql .=' where datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
$sqlMSG='select id, DATE_FORMAT(datum, "%d-%m-%Y"), message from messages';
$sqlMSG .=' where datum>=' . date('Ymd',$date) . ' and datum<=' . date('Ymd',strtotime("+364 day", $date));
$sqlMSG .=' order by datum, message';
$resultMSG = mysqli_query($con, $sqlMSG);
if ($resultMSG){
echo '<ul class="kies hide">';
while(list($id, $datum, $msg)= mysqli_fetch_row($resultMSG)){
echo '<li class="kies"><input type="button" value="Verwijder" onClick="verwijder(' . $id . ')">' . ' ' . $msg . ' (' . $datum . ')</li>';
}
echo '<li class="clear kies"></li></ul>';
}
}
$sql .=' order by datum, achternaam, voornaam';
$result=mysqli_query($con, $sql);
if ($result){
echo '<ul class="kies hide">';
while(list($afwezigID, $id, $vnaam, $anaam, $datum)= mysqli_fetch_row($result)){
echo '<li class="kies"><input type="button" value="Ik kom toch" onClick="komtToch(' . $afwezigID . ')">' . ' ' . $vnaam . ' ' . $anaam . ' (' . $datum . ')</li>';
}
echo '<li class="clear kies"></li></ul>';
}
?>
<br><br>
<hr>
<table>
<?php
for ($j = 1; $j < 9; $j++) {
echo '<tr>';
$rij2='<tr>';
for ($i = 1; $i <= 6; $i++) {
$rij2.='<td class="naam">';
echo '<td class="datum">'. date('d/m/Y',$date) .'</td>';
$sql='select message,opmerking
FROM messages where datum='.date('Ymd',$date);
$result=mysqli_query($con, $sql);
if ($result){
while(list($msg, $MSGopmerking)= mysqli_fetch_row($result)){
$rij2.= '<div style="color:red;"';
if ($MSGopmerking !=''){
$rij2.= ' title="'.$MSGopmerking.'"';
}
$rij2.= '>' . $msg . '</div>';
}
}
$sql='select voornaam, achternaam, opmerking
FROM afwezig
INNER JOIN post_leden
on post_leden.ID = afwezig.naamid where datum='.date('Ymd',$date).' order by achternaam, voornaam';
//echo $sql .'<br>';
$result=mysqli_query($con, $sql);
if ($result){
while(list($vnaam, $anaam, $opmerking)= mysqli_fetch_row($result)){
$rij2.= '<div';
if ($opmerking !=''){
$rij2.= ' title="'.$opmerking.'"';
}
$rij2.= '>' . $vnaam. ' ' . $anaam . '</div>';
}
}
$rij2.='</td>';
$date = strtotime("+7 day", $date);
}
echo $rij2 . '</tr>';
}
?>
</table>
</body>
</html>
<?php
mysqli_close($con);
?>
Bedankt Jan
Er zijn nog geen reacties op dit bericht.