Agenda
heb nu dat ik de dagview krijg, alleen als ik op volgende en vorige klik springt hij een week vooruit.
Hij is wel in het duits geprogrammmeert, maar ik denk niet dat het wat uitmaakt als programmeur.
Hier is de code:
Quote:
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<?PHP
class calendar {
private $sIdentNumber;
private $nCalendarBreite;
private $nCalendarHoehe;
private $nAnzZeilenProStunde;
private $nZeilenHoehe;
private $nMode;
private $nTage;
private $nKW;
private $nJahr;
private $aTage = array();
private $aEvent = array();
private $nDisplayStundenVon;
private $nDisplayStundenBis;
private $bDisplayArbeitszeit;
private $nArbeitszeitVon;
private $nArbeitszeitBis;
private $aArbeitsTage = array();
private $aGeprueft = array();
private $aZusammen = array();
public function setCalenderBreite($nBreite) {
$this->nCalendarBreite = $nBreite;
}
public function setCalenderHoehe($nHoehe) {
$this->nCalendarHoehe = $nHoehe;
}
public function setAnzZeilenProStunde($nZeilen) {
$this->nAnzZeilenProStunde = intval($nZeilen);
}
private function setAnzTage($nTage) {
$this->nTage = intval($nTage);
}
public function getDays() {
return $this->aTage;
}
public function setKW($nKW, $nJahr) {
$this->nJahr = intval($nJahr);
$this->nKW = intval($nKW);
$this->setDays();
}
public function setZeilenHoehe($nZeilenHoehe) {
$this->nZeilenHoehe = $nZeilenHoehe;
}
public function showArbeitszeit($bShow) {
$this->bDisplayArbeitszeit = (bool) $bShow;
}
public function setArbeitszeit($nVon, $nBis) {
$this->nArbeitszeitVon = intval($nVon);
$this->nArbeitszeitBis = intval($nBis);
}
public function setArbeitstage($aArbeitstage) {
$this->aArbeitsTage = $aArbeitstage;
}
/**
* 1 = ganze Woche (Mo-So); 2 = Arbeitswoche (Mo-Fr);
*
* @param int $nMode
* @param date $dtVon (DD.MM.YYYY)
* @param date $dtBis (DD.MM.YYYY)
*/
public function setMode($nMode) {
$this->nMode = intval($nMode);
if ($nMode==1) {
$this->nTage = 1;
}
elseif ($nMode==2) {
$this->nTage = 1;
}
}
public function setStunden($nVon, $nBis) {
$this->nDisplayStundenVon = intval($nVon);
$this->nDisplayStundenBis = intval($nBis);
}
private function setDefaultSettings() {
$this->setCalenderBreite('100%');
$this->setCalenderHoehe(false);
$this->setAnzZeilenProStunde(2);
$this->setZeilenHoehe(20);
$this->setMode(1);
$this->setKW(date('W', mktime()), date('Y', mktime()));
$this->setStunden(0, 23);
$this->setArbeitszeit(8, 17);
$this->showArbeitszeit(false);
$this->setArbeitstage(array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'));
}
public function __construct() {
$this->setDefaultSettings();
if ($_COOKIE['phpkalender_identid']) {
$this->sIdentNumber = $_COOKIE['phpkalender_identid'];
}
else {
$this->sIdentNumber = time();
//setcookie("phpkalender_identid", $this->sIdentNumber);
}
}
private function getFirstDayOfWeek($year, $weeknr) {
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'weeks', $monday);
}
/**
* Der Typ bestimmt, ob Start oder EndZeile gemeint ist
*
* @param unknown_type $nTime
* @param unknown_type $nTyp
*/
private function getZeile($nTime, $nTyp) {
$nMinute = substr($nTime, 2, 2);
$nStunde = substr($nTime, 0, 2);
$nReturn = NULL;
$nDivisor = 60/$this->nAnzZeilenProStunde;
$nErgebnisGenau = $nMinute/floor($nDivisor);
if(strpos($nErgebnisGenau, '.')) {
$nZeile = ceil($nErgebnisGenau);
}
else {
if ($nTyp==0) {
$nStunde = (int) $nStunde;
$nZeile = (int) $nErgebnisGenau + 1;
} else{
$nZeile = (int) $nErgebnisGenau;
if ($nZeile==0) {
$nStunde = (int) ($nStunde - 1);
$nZeile = $this->nAnzZeilenProStunde;
}
else {
$nStunde = (int) $nStunde;
}
}
}
return (int) $nStunde.'.'. (int) $nZeile;
}
private function getTopPositionFromEvent($nStart) {
$aPos = explode('.', (string) $nStart);
$nTop = $aPos[0]*$this->nZeilenHoehe*$this->nAnzZeilenProStunde;
$nTop = $nTop + (($aPos[1]*$this->nZeilenHoehe)-$this->nZeilenHoehe);
$nTop = $nTop - ($this->nDisplayStundenVon*$this->nZeilenHoehe*$this->nAnzZeilenProStunde);
return $nTop;
}
private function getIndexFromDay($dtDatum) {
for ($i=1; $i<=$this->nTage; $i++) {
if ($this->aTage[$i]['datum']==$dtDatum) {
return $i;
}
}
}
private function replaceDayDesc($sDesc) {
$sReturn = str_replace('Sun', 'Zondag', str_replace('Sat', 'Zaterdag', str_replace('Fri', 'Vrijdag', str_replace('Thu', 'Donderdag', str_replace('Wed', 'Woensdag', str_replace('Tue', 'Dinsdag', str_replace('Mon', 'Maandag', $sDesc)))))));
return $sReturn;
}
private function setDays() {
$nKW = $this->nKW;
$nJahr = $this->nJahr;
$nStart = $this->getFirstDayOfWeek($nJahr, $nKW);
for ($i=1; $i<=$this->nTage; $i++) {
$nAktuell = $nStart + (60*60*24*($i-1));
$this->aTage[$i]['timestamp'] = $nAktuell;
$this->aTage[$i]['datum'] = date('Ymd', $nAktuell);
$this->aTage[$i]['formatiert'] = date('d.m.Y', $nAktuell);
$this->aTage[$i]['mysql'] = date('Y-d-m', $nAktuell).' 00:00:00';
$this->aTage[$i]['kuerzel'] = date('D', $nAktuell);
$this->aTage[$i]['bez'] = $this->replaceDayDesc(date('D', $nAktuell));
}
}
private function setSpaltenanzahl() {
$this->aZusammen = array();
$this->aGeprueft = array();
$sSql = "select nlfdevent
from event
where UNIX_TIMESTAMP(dtvon) >= ".$this->aTage[1]['timestamp']."
and UNIX_TIMESTAMP(dtbis) <= ".($this->aTage[$this->nTage]['timestamp']+(24*60*60))."
and date_format(dtvon, '%k') >= ".$this->nDisplayStundenVon."
and date_format(dtbis, '%k') <= ".($this->nDisplayStundenBis+1)."
and dtvon < dtbis ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$this->aZusammen = array();
if (!in_array($row['nlfdevent'], $this->aGeprueft)) {
$this->getEventZusammenhang($row['nlfdevent']);
$sInString = implode(', ', array_unique($this->aZusammen));
$sSql3 = "select max(nanz) nanz from (
SELECT count(*) nanz, szelle
FROM temp
WHERE szelle IN (
SELECT t1.*
FROM (
SELECT szelle
FROM temp
WHERE nlfdevent in (".$sInString.")
)t1
)
and ndatum = (select date_format(dtvon, '%Y%m%d') from event where nlfdevent = ".$row['nlfdevent'].")
and nidentid = ".$this->sIdentNumber."
group by szelle
) t2";
$result3 = mysql_query($sSql3);
while ($row3 = @mysql_fetch_assoc($result3)) {
$sSql2 = "update temp set nanzspalten = ".$row3['nanz']." where nlfdevent in (".$sInString.")";
mysql_query($sSql2);
}
}
}
}
private function getEventZusammenhang($nLfdEvent) {
array_push($this->aGeprueft, $nLfdEvent);
$sSql = " SELECT DISTINCT nlfdevent
FROM temp
WHERE szelle IN (
SELECT t1.*
FROM (
SELECT szelle
FROM temp
WHERE nlfdevent = ".$nLfdEvent."
)t1
)
and ndatum = (select date_format(dtvon, '%Y%m%d') from event where nlfdevent = ".$nLfdEvent.")
and nidentid = ".$this->sIdentNumber." ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
if (!in_array($row['nlfdevent'], $this->aZusammen)) {
array_push($this->aZusammen, (int) $nLfdEvent);
}
if (!in_array($row['nlfdevent'], $this->aGeprueft)) {
$this->getEventZusammenhang($row['nlfdevent']);
}
}
}
private function getHeightFromEvent($nEnde, $nTop) {
$aPos = explode('.', (string) $nEnde);
$nBottom = $aPos[0]*$this->nZeilenHoehe*$this->nAnzZeilenProStunde;
$nBottom = $nBottom + $aPos[1]*$this->nZeilenHoehe;
$nBottom = $nBottom - ($this->nDisplayStundenVon*$this->nZeilenHoehe*$this->nAnzZeilenProStunde);
$nHeight = $nBottom - $nTop;
return $nHeight;
}
public function updateEvent($nId, $aColumns) {
$sSql = " update event set ";
foreach ($aColumns as $key => $value) {
$sSql.= $key." = '".strip_tags($value)."', ";
}
$sSql.= " nlfdevent = ". intval($nId);
$sSql.= " where nlfdevent = ".intval($nId);
mysql_query($sSql);
}
public function removeEvent($nId) {
$sSql = "delete from event
where nlfdevent = ".intval($nId);
mysql_query($sSql);
}
public function addEvent($sBez, $sBesch, $dtVon, $dtBis, $sColor) {
if ($dtVon<$dtBis && substr($dtVon,0,10) == substr($dtBis,0,10)) {
$sSql = "insert into event (
seventbez,
seventbeschreibung,
dtvon,
dtbis,
scolor
) values (
'".strip_tags($sBez)."',
'".strip_tags($sBesch)."',
'".strip_tags($dtVon)."',
'".strip_tags($dtBis)."',
'".strip_tags($sColor)."'
)";
mysql_query($sSql);
}
return mysql_insert_id();
}
public function getEventDetails($nId) {
$sSql = " select nlfdevent,
seventbez,
UNIX_TIMESTAMP(dtvon) dtvontimestamp,
date_format( dtvon, '%H:%i' ) dtvon,
date_format( dtvon, '%Y-%m-%d' ) datum,
date_format( dtvon, '%Y%m%d' ) stagvon,
date_format( dtvon, '%H%i' ) suhrzeitvon,
date_format( dtbis, '%H:%i' ) dtbis,
date_format( dtbis, '%Y%m%d' ) stagbis,
date_format( dtbis, '%H%i' ) suhrzeitbis,
date_format( dtvon, '%d' ) tag,
date_format( dtvon, '%m' ) monat,
date_format( dtvon, '%Y' ) jahr,
scolor
from event
where nlfdevent = ".$nId." ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$aEvent = array();
$aEvent['id'] = $row['nlfdevent'];
$aEvent['datum'] = $row['datum'];
$aEvent['tag'] = $row['tag'];
$aEvent['monat'] = $row['monat'];
$aEvent['jahr'] = $row['jahr'];
$aEvent['dtDatum'] = $row['stagvon'];
$aEvent['dtStart'] = $row['suhrzeitvon'];
$aEvent['dtEnde'] = $row['suhrzeitbis'];
$aEvent['sColor'] = $row['scolor'];
$aEvent['dtVon'] = $row['dtvon'];
$aEvent['dtBis'] = $row['dtbis'];
$aEvent['bez'] = $row['seventbez'];
$aEvent['timest'] = $row['dtvontimestamp'];
}
mysql_free_result($result);
return $aEvent;
}
private function getEvents() {
@mysql_query("delete from temp where nidentid = ".$this->sIdentNumber);
$sSql = " select nlfdevent,
seventbez,
UNIX_TIMESTAMP(dtvon) dtvontimestamp,
date_format( dtvon, '%H:%i' ) dtvon,
date_format( dtvon, '%Y%m%d' ) stagvon,
date_format( dtvon, '%H%i' ) suhrzeitvon,
date_format( dtbis, '%H:%i' ) dtbis,
date_format( dtbis, '%Y%m%d' ) stagbis,
date_format( dtbis, '%H%i' ) suhrzeitbis,
scolor
from event
where UNIX_TIMESTAMP(dtvon) >= ".$this->aTage[1]['timestamp']."
and UNIX_TIMESTAMP(dtbis) <= ".($this->aTage[$this->nTage]['timestamp']+(24*60*60))."
and date_format(dtvon, '%k') >= ".$this->nDisplayStundenVon."
and date_format(dtbis, '%k') <= ".($this->nDisplayStundenBis+1)."
and dtvon < dtbis
order by dtvon asc, (dtbis - dtvon) desc ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nIndex = $this->getIndexFromDay($row['stagvon']);
if (!is_array($this->aEvent[$nIndex])) {
$this->aEvent[$nIndex] = array();
}
$aEventAkt = array();
$aEventAkt['id'] = $row['nlfdevent'];
$aEventAkt['dtDatum'] = $row['stagvon'];
$aEventAkt['dtStart'] = $row['suhrzeitvon'];
$aEventAkt['dtEnde'] = $row['suhrzeitbis'];
$aEventAkt['nStart'] = $this->getZeile($aEventAkt['dtStart'], 0);
$aEventAkt['nEnde'] = $this->getZeile($aEventAkt['dtEnde'], 1);
$aEventAkt['nTop'] = $this->getTopPositionFromEvent($aEventAkt['nStart']);
$aEventAkt['nHeight'] = $this->getHeightFromEvent($aEventAkt['nEnde'], $aEventAkt['nTop']);
$aEventAkt['sColor'] = $row['scolor'];
$aEventAkt['dtVon'] = $row['dtvon'];
$aEventAkt['dtBis'] = $row['dtbis'];
$aEventAkt['bez'] = $row['seventbez'];
$aEventAkt['timest'] = $row['dtvontimestamp'];
array_push($this->aEvent[$nIndex], $aEventAkt);
}
mysql_free_result($result);
for ($t=1; $t<=$this->nTage; $t++) {
if (is_array($this->aEvent[$t])) {
for ($y=0; $y<count($this->aEvent[$t]); $y++) {
$aStart = explode('.', $this->aEvent[$t][$y]['nStart']);
$aEnde = explode('.', $this->aEvent[$t][$y]['nEnde']);
$nStart = $aStart[0].$aStart[1];
$nEnde = $aEnde[0].$aemde[1];
for ($i=$aStart[0]; $i<=$aEnde[0]; $i++) {
for ($x=1; $x<=$this->nAnzZeilenProStunde; $x++) {
$nPosAkt = $i.$x;
if (($x>=$aStart[1] && $i==$aStart[0]) || ($i<$aEnde[0] && $i!=$aStart[0]) || ($i==$aEnde[0] && $x<=$aEnde[1])) {
$nAktuell = ($i.str_pad($x, 5, '0', STR_PAD_LEFT));
$nMax = intval($aEnde[0].str_pad($aEnde[1], 5, '0', STR_PAD_LEFT));
$nMin = ($aStart[0].str_pad($aStart[1], 5, '0', STR_PAD_LEFT));
if (intval($nAktuell)>=intval ($nMin) && intval ($nAktuell)<= intval ($nMax)) {
$sSql = "insert into temp (
nidentid,
nlfdevent,
szelle,
nanzbelegt,
ndatum
) values (
'".$this->sIdentNumber."',
'".$this->aEvent[$t][$y]['id']."',
'".$i.".".$x."',
'0',
'".$this->aEvent[$t][$y]['dtDatum']."'
)";
@mysql_query($sSql);
}
}
}
}
}
}
}
$this->setSpaltenanzahl();
for ($t=1; $t<=$this->nTage; $t++) {
if (is_array($this->aEvent[$t])) {
for ($y=0; $y<count($this->aEvent[$t]); $y++) {
$sSql = "select distinct nanzspalten from temp where nlfdevent = ".$this->aEvent[$t][$y]['id'];
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nAnzspalten = $row['nanzspalten'];
$nWidth = floor(100 / $row['nanzspalten']);
}
mysql_free_result($result);
$sSql = NULL;
// Bau neues SQL für Pos zusammen
for ($i=1; $i<=$nAnzspalten; $i++) {
if ($i!=1) {
$sSql .= "union all ";
}
$sSql .= "(select count(*) nbelegt, ".$i." npos from temp where nidentid = ".$this->sIdentNumber." and szelle in (SELECT t1.* from (select szelle from temp where nlfdevent = ".$this->aEvent[$t][$y]['id'].") t1) and nposbelegt = ".$i." and ndatum = ".$this->aEvent[$t][$y]['dtDatum'].") ";
}
$sSql .= "order by 1,2 limit 1 ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nPos = $row['npos'];
$nLeft = ($nPos-1)*$nWidth;
}
@mysql_free_result($result);
$this->aEvent[$t][$y]['nWidth'] = $nWidth.'%';
$this->aEvent[$t][$y]['nLeft'] = $nLeft.'%';
$sSql = "update temp set nposbelegt = ".$nPos." where nlfdevent = ".$this->aEvent[$t][$y]['id'];
@mysql_query($sSql);
}
}
}
// Nochmal zur sicherheit alles ausm temp raus
@mysql_query("delete from temp where nidentid = ".$this->sIdentNumber);
return $this->aEvent;
}
public function fetchTable() {
echo "<table border='0' id='myTable' style='width:100%; margin-top:-2px;' style='overflow:hidden'>";
echo "<tbody id='myTableBody'>";
$this->fetchEvents();
// Berechenen der Breite von den Spalten (prozentual)
$num_prozent = 100 / $this->nTage;
// Schleife für gesamten Stunden
for ($i=$this->nDisplayStundenVon; $i<=$this->nDisplayStundenBis; $i++) {
// Schleife für die Zeilen einer Stunde - Standart sind 2, können aber über Funktion verändert werden
for ($x=1; $x<=$this->nAnzZeilenProStunde; $x++) {
echo "<tr>";
if ($x==1) {
echo "<td unselectable='on' rowspan='".$this->nAnzZeilenProStunde."' ".($i==$this->nDisplayStundenVon?' id=\'CalendarZelle0\'':"")." class='tableDateCell' style=' -moz-user-select: none; ";
if ($i==$this->nDisplayStundenBis) {
echo " border-bottom:0px; ";
}
echo "'> ";
echo "<div unselectable='on'>";
echo $i."<span>00</span>";
echo "</div>";
echo "</td>";
}
// Schleife für die Zeilen der Tage (Spalten)
for ($y=1; $y<=$this->nTage; $y++) {
echo "<td class='";
// Leider wichtig für die Unterschiedlichen Rahmen
if ($x==1 && $this->nAnzZeilenProStunde==1) {
echo "tableDataCell_dunkel_dunkel";
}
elseif ($x==1 && $this->nAnzZeilenProStunde>1) {
echo "tableDataCell_dunkel_hell";
}
elseif ($x==$this->nAnzZeilenProStunde) {
echo "tableDataCell_hell_dunkel";
}
else {
echo "tableDataCell_hell_hell";
}
echo "' style='padding:0px; width:".$num_prozent."%; height:".$this->nZeilenHoehe."px; vertical-align:top; -moz-user-select: none; ";
// Wenn letzter Tag, keinen rechten Rahmen zeigen
if ($y==$this->nTage) {
echo "border-right: 0px;";
}
if ($i==$this->nDisplayStundenBis && $x==$this->nAnzZeilenProStunde) {
echo "border-bottom: 0px;";
}
// Wenn Arbeitszeit angezeigt werden soll, dann andere Hintergrundfarbe
if ($this->bDisplayArbeitszeit==true) {
if ($i>=$this->nArbeitszeitVon && $i<$this->nArbeitszeitBis && in_array($this->aTage[$y]['kuerzel'], $this->aArbeitsTage)) {
echo "background-color:#ffffd5";
}
}
echo "'";
// ID´s in erster Zeile setzen, damit später mit Javascript der Header Richtig gesetzt werden kann
if ($i==$this->nDisplayStundenVon && $x==1) {
echo " id='CalendarZelle".$y."'";
}
$sId = str_pad($y, 4, "0", STR_PAD_LEFT).'.'.str_pad($i, 4, "0", STR_PAD_LEFT).'.'.str_pad($x, 4, "0", STR_PAD_LEFT);
echo " unselectable='on' ><div id='".$sId."' onmousedown='newEvent(this);' unselectable='on' style='-moz-user-select: none; /*background-color:#3399ff;*/ width:100%; height:".($this->nZeilenHoehe-1)."px; margin:0px; padding:0px; font-size:1px;'></div></td>";
}
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
}
public function fetchEvents() {
echo "<tr style='height:0px;' id='eventContainer'>";
echo "<td style='padding:0px; height:0px; maring:0px; border: 0px solid #a0a0a0'>";
echo "</td>";
// Events holen
$aEvent = $this->getEvents();
for ($i=1; $i<=$this->nTage; $i++) {
echo "<td style='padding:0px; height:0px; maring:0px; border: 0px solid #a0a0a0'>";
echo "<div style='display: block; margin-right: 5px; position: relative; height: 1px; font-size: 0px; line-height: 1.2; margin-top: 0px;' id='eventTag".$i."'>";
if (is_array($this->aEvent[$i])) {
for ($y=0; $y<count($aEvent[$i]); $y++) {
echo " <div class='termin' ondblclick='alert(\"Jetzt Termin aendern: \"+".$aEvent[$i][$y]['id'].")' id='event_".$aEvent[$i][$y]['id']."' unselectable='on' style='overflow: hidden; -moz-user-select: none; position: absolute; top:".($aEvent[$i][$y]['nTop']+1)."px; font-family: Tahoma; font-size: 8pt; color: rgb(0, 0, 0); left: ".$aEvent[$i][$y]['nLeft']."; width: ".$aEvent[$i][$y]['nWidth']."; height: ".($aEvent[$i][$y]['nHeight']+1)."px; background-color: rgb(0, 0, 0);' onmousedown='dragstart(this)' onmouseover='overstart(this)' onmouseout='overend()'>";
echo " <div unselectable='on' style='position: absolute; width: 100%; text-align: right;'><img id='eventRemove_".$aEvent[$i][$y]['id']."' onmouseover='$(\"event_".$aEvent[$i][$y]['id']."\").onmousedown = function() {null;}' onmouseout='$(\"event_".$aEvent[$i][$y]['id']."\").onmousedown = function() {dragstart(this);}' onclick='removeEvent(this.id.substr(12).toString())' src='img/del.gif' style='margin-right: 2px; margin-top: 2px; cursor: pointer;' width='10' height='10'></div>";
echo " <div unselectable='on' style='height: 1px; line-height: 1px; font-size: 0px; width: 1px;'><!-- --></div>";
echo " <div id='eventContent_".$aEvent[$i][$y]['id']."' class='event' style=' border-right: 1px solid rgb(0, 0, 0); overflow: hidden; margin-top: 0px; height: ".($aEvent[$i][$y]['nHeight']-1)."px; background-color: rgb(255, 255, 255);' unselectable='on'>";
echo " <div id='eventColor_".$aEvent[$i][$y]['id']."' style='position: absolute; left: 0px; width: 5px; height: ".($aEvent[$i][$y]['nHeight']-1)."px; background-color: #".$aEvent[$i][$y]['sColor']."; font-size: 1px;' unselectable='on'></div>";
echo " <div style='position: absolute; left: 5px; top: 0px; width: 1px; background-color: rgb(0, 0, 0); height: 100%;' unselectable='on'></div>";
echo " <div unselectable='on' style='padding-left: 8px;'>".$aEvent[$i][$y]['bez']." (".$aEvent[$i][$y]['dtVon']." - ".$aEvent[$i][$y]['dtBis'].")</div>";
echo " </div>";
echo " </div>";
}
}
echo "</div>";
echo "</td>";
}
echo "</tr>";
}
public function fetchTableHeader() {
echo "<tr>";
echo "<td id='calendarHeaderZelle0'> </td>";
for ($y=1; $y<=$this->nTage; $y++) {
echo "<td unselectable='on' id='calendarHeaderZelle".$y."' style='overflow:hidden; -moz-user-select: none; '>";
echo "<div unselectable='on' style='padding-bottom:3px;padding-top:3px;overflow:hidden; white-space:nowrap; -moz-user-select: none; '>";
echo $this->aTage[$y]['bez'].", ";
echo "<br />";
echo "<span style='font-weight:normal;'>".$this->aTage[$y]['formatiert']."</span>";
echo "</div>";
echo "</td>";
}
echo "<td id='calendarHeaderZelleSpacer' ".($this->nCalendarHoehe==false?'':'style=\'width:16px;\'')."></td>";
echo "</tr>";
}
public function getNewEventLayer($nMode, $sBetreff, $sText, $sFarbe, $dtDatum, $dtVon, $dtBis) {
echo "<form method='get' action='".$PHP_SELF."'>";
if ($nMode==1) {
echo "<input type='hidden' name='terminAdd' value='true'>";
echo "<input type='hidden' name='aktion' value='newTermin'>";
} else {
echo "<input type='hidden' name='terminUpdate' value='true'>";
}
echo "<table style='width:100%;' id='newEventLayer'>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Titel: </td>
<td colspan='2'><input type='text' name='sBetreff' style='width:100%' value='".$sBetreff."'></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Kleur: </td>
<td><input type='text' name='sFarbe' readonly id='sFarbe' value='".($sFarbe==''?'0000ff':$sFarbe)."' style='width:85px'></td>
<td>
<div onclick='document.getElementById(\"sFarbe\").value=\"0000ff\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#0000ff'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"800080\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#800080'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"ffffff\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#ffffff'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"ff0000\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#ff0000'> </div>
</td
</tr>
<tr>
<td colspan='3'><hr rules='all'></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Van: </td>
<td><input type='text' name='dtDatum' value='".$dtDatum."' style='width:85px'></td>
<td> Om: <input type='text' name='dtVon' value='".$dtVon."' style='width:50px'> Uur</td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Tot: </td>
<td style='width:1%'> </td>
<td style='width:98%'> Om: <input type='text' name='dtBis' value='".$dtBis."' style='width:50px'> Uur</td>
</tr>
<tr>
<td colspan='3'><hr></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Beschrijving: </td>
<td colspan='2'><textarea style='width:100%;' name='sBetreff' rows='5'>".$sText."</textarea></td>
</tr>
<tr>
<td colspan='3'><hr></td>
</tr>
<tr>
<td colspan='3' style='text-align:right;'><input type='submit' value='Plaatsen'/></td>
</tr>
</table>
</form>";
}
public function init() {
echo "<table style='width:".($this->nCalendarBreite)."' class='CalendarTableHeader' id='CalendarTableHeader'>";
echo "<tbody id='myTableHeader'>";
$this->fetchTableHeader();
echo "</tbody>";
echo "</table>";
echo "<div id='layer'><img src='img/loader.gif'></div>";
echo "<div id='CalendarTableBody' style='margin:0px; margin-top:-1px; padding:0px; overflow:auto; width:".$this->nCalendarBreite."; border-right: 1px solid #a0a0a0; border-bottom: 1px solid #a0a0a0; border-top: 1px solid #a0a0a0; ".($this->nCalendarHoehe!=false?'height:'.$this->nCalendarHoehe.'px;':'')."' >";
$this->fetchTable();
echo "</div>";
echo "<script>";
echo "
var nZelleHeight = ".$this->nZeilenHoehe.";
var nZelleWidth = $('CalendarZelle1').offsetWidth;
function setSize() {
var nSpacer = 0;
for (i=0; i<".$this->nTage."; i++) {
objHeaderZelle = $('calendarHeaderZelle'+i);
if (i!=0)
objDataZelle = $('CalendarZelle1');
else
objDataZelle = $('CalendarZelle0');
nSpacer = nSpacer + objDataZelle.offsetWidth-1;
objHeaderZelle.style.width = objDataZelle.offsetWidth-1;
}
$('CalendarTableHeader').style.width = $('CalendarTableBody').offsetWidth;
}
addLoadEvent(function() {
setSize();
nZelleWidth = $('CalendarZelle1').offsetWidth;
draginit();
objBody = document.getElementsByTagName('body')[0];
nAnzZeilenProStunde = ".intval($this->nAnzZeilenProStunde).";
nZeilenHoehe = ".intval($this->nZeilenHoehe).";
nMode = ".intval($this->nMode).";
nTage = ".intval($this->nTage).";
nKW = ".intval($this->nKW).";
nJahr = ".intval($this->nJahr).";
nDisplayStundenVon = ".intval($this->nDisplayStundenVon).";
nDisplayStundenBis = ".intval($this->nDisplayStundenBis).";
nTopGrid = getOffsetTop($('CalendarZelle1'));
});
addResizeEvent(function() {
setSize();
nZelleWidth = $('CalendarZelle1').offsetWidth;
});
";
echo "</script>";
}
}
?>
class calendar {
private $sIdentNumber;
private $nCalendarBreite;
private $nCalendarHoehe;
private $nAnzZeilenProStunde;
private $nZeilenHoehe;
private $nMode;
private $nTage;
private $nKW;
private $nJahr;
private $aTage = array();
private $aEvent = array();
private $nDisplayStundenVon;
private $nDisplayStundenBis;
private $bDisplayArbeitszeit;
private $nArbeitszeitVon;
private $nArbeitszeitBis;
private $aArbeitsTage = array();
private $aGeprueft = array();
private $aZusammen = array();
public function setCalenderBreite($nBreite) {
$this->nCalendarBreite = $nBreite;
}
public function setCalenderHoehe($nHoehe) {
$this->nCalendarHoehe = $nHoehe;
}
public function setAnzZeilenProStunde($nZeilen) {
$this->nAnzZeilenProStunde = intval($nZeilen);
}
private function setAnzTage($nTage) {
$this->nTage = intval($nTage);
}
public function getDays() {
return $this->aTage;
}
public function setKW($nKW, $nJahr) {
$this->nJahr = intval($nJahr);
$this->nKW = intval($nKW);
$this->setDays();
}
public function setZeilenHoehe($nZeilenHoehe) {
$this->nZeilenHoehe = $nZeilenHoehe;
}
public function showArbeitszeit($bShow) {
$this->bDisplayArbeitszeit = (bool) $bShow;
}
public function setArbeitszeit($nVon, $nBis) {
$this->nArbeitszeitVon = intval($nVon);
$this->nArbeitszeitBis = intval($nBis);
}
public function setArbeitstage($aArbeitstage) {
$this->aArbeitsTage = $aArbeitstage;
}
/**
* 1 = ganze Woche (Mo-So); 2 = Arbeitswoche (Mo-Fr);
*
* @param int $nMode
* @param date $dtVon (DD.MM.YYYY)
* @param date $dtBis (DD.MM.YYYY)
*/
public function setMode($nMode) {
$this->nMode = intval($nMode);
if ($nMode==1) {
$this->nTage = 1;
}
elseif ($nMode==2) {
$this->nTage = 1;
}
}
public function setStunden($nVon, $nBis) {
$this->nDisplayStundenVon = intval($nVon);
$this->nDisplayStundenBis = intval($nBis);
}
private function setDefaultSettings() {
$this->setCalenderBreite('100%');
$this->setCalenderHoehe(false);
$this->setAnzZeilenProStunde(2);
$this->setZeilenHoehe(20);
$this->setMode(1);
$this->setKW(date('W', mktime()), date('Y', mktime()));
$this->setStunden(0, 23);
$this->setArbeitszeit(8, 17);
$this->showArbeitszeit(false);
$this->setArbeitstage(array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'));
}
public function __construct() {
$this->setDefaultSettings();
if ($_COOKIE['phpkalender_identid']) {
$this->sIdentNumber = $_COOKIE['phpkalender_identid'];
}
else {
$this->sIdentNumber = time();
//setcookie("phpkalender_identid", $this->sIdentNumber);
}
}
private function getFirstDayOfWeek($year, $weeknr) {
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'weeks', $monday);
}
/**
* Der Typ bestimmt, ob Start oder EndZeile gemeint ist
*
* @param unknown_type $nTime
* @param unknown_type $nTyp
*/
private function getZeile($nTime, $nTyp) {
$nMinute = substr($nTime, 2, 2);
$nStunde = substr($nTime, 0, 2);
$nReturn = NULL;
$nDivisor = 60/$this->nAnzZeilenProStunde;
$nErgebnisGenau = $nMinute/floor($nDivisor);
if(strpos($nErgebnisGenau, '.')) {
$nZeile = ceil($nErgebnisGenau);
}
else {
if ($nTyp==0) {
$nStunde = (int) $nStunde;
$nZeile = (int) $nErgebnisGenau + 1;
} else{
$nZeile = (int) $nErgebnisGenau;
if ($nZeile==0) {
$nStunde = (int) ($nStunde - 1);
$nZeile = $this->nAnzZeilenProStunde;
}
else {
$nStunde = (int) $nStunde;
}
}
}
return (int) $nStunde.'.'. (int) $nZeile;
}
private function getTopPositionFromEvent($nStart) {
$aPos = explode('.', (string) $nStart);
$nTop = $aPos[0]*$this->nZeilenHoehe*$this->nAnzZeilenProStunde;
$nTop = $nTop + (($aPos[1]*$this->nZeilenHoehe)-$this->nZeilenHoehe);
$nTop = $nTop - ($this->nDisplayStundenVon*$this->nZeilenHoehe*$this->nAnzZeilenProStunde);
return $nTop;
}
private function getIndexFromDay($dtDatum) {
for ($i=1; $i<=$this->nTage; $i++) {
if ($this->aTage[$i]['datum']==$dtDatum) {
return $i;
}
}
}
private function replaceDayDesc($sDesc) {
$sReturn = str_replace('Sun', 'Zondag', str_replace('Sat', 'Zaterdag', str_replace('Fri', 'Vrijdag', str_replace('Thu', 'Donderdag', str_replace('Wed', 'Woensdag', str_replace('Tue', 'Dinsdag', str_replace('Mon', 'Maandag', $sDesc)))))));
return $sReturn;
}
private function setDays() {
$nKW = $this->nKW;
$nJahr = $this->nJahr;
$nStart = $this->getFirstDayOfWeek($nJahr, $nKW);
for ($i=1; $i<=$this->nTage; $i++) {
$nAktuell = $nStart + (60*60*24*($i-1));
$this->aTage[$i]['timestamp'] = $nAktuell;
$this->aTage[$i]['datum'] = date('Ymd', $nAktuell);
$this->aTage[$i]['formatiert'] = date('d.m.Y', $nAktuell);
$this->aTage[$i]['mysql'] = date('Y-d-m', $nAktuell).' 00:00:00';
$this->aTage[$i]['kuerzel'] = date('D', $nAktuell);
$this->aTage[$i]['bez'] = $this->replaceDayDesc(date('D', $nAktuell));
}
}
private function setSpaltenanzahl() {
$this->aZusammen = array();
$this->aGeprueft = array();
$sSql = "select nlfdevent
from event
where UNIX_TIMESTAMP(dtvon) >= ".$this->aTage[1]['timestamp']."
and UNIX_TIMESTAMP(dtbis) <= ".($this->aTage[$this->nTage]['timestamp']+(24*60*60))."
and date_format(dtvon, '%k') >= ".$this->nDisplayStundenVon."
and date_format(dtbis, '%k') <= ".($this->nDisplayStundenBis+1)."
and dtvon < dtbis ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$this->aZusammen = array();
if (!in_array($row['nlfdevent'], $this->aGeprueft)) {
$this->getEventZusammenhang($row['nlfdevent']);
$sInString = implode(', ', array_unique($this->aZusammen));
$sSql3 = "select max(nanz) nanz from (
SELECT count(*) nanz, szelle
FROM temp
WHERE szelle IN (
SELECT t1.*
FROM (
SELECT szelle
FROM temp
WHERE nlfdevent in (".$sInString.")
)t1
)
and ndatum = (select date_format(dtvon, '%Y%m%d') from event where nlfdevent = ".$row['nlfdevent'].")
and nidentid = ".$this->sIdentNumber."
group by szelle
) t2";
$result3 = mysql_query($sSql3);
while ($row3 = @mysql_fetch_assoc($result3)) {
$sSql2 = "update temp set nanzspalten = ".$row3['nanz']." where nlfdevent in (".$sInString.")";
mysql_query($sSql2);
}
}
}
}
private function getEventZusammenhang($nLfdEvent) {
array_push($this->aGeprueft, $nLfdEvent);
$sSql = " SELECT DISTINCT nlfdevent
FROM temp
WHERE szelle IN (
SELECT t1.*
FROM (
SELECT szelle
FROM temp
WHERE nlfdevent = ".$nLfdEvent."
)t1
)
and ndatum = (select date_format(dtvon, '%Y%m%d') from event where nlfdevent = ".$nLfdEvent.")
and nidentid = ".$this->sIdentNumber." ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
if (!in_array($row['nlfdevent'], $this->aZusammen)) {
array_push($this->aZusammen, (int) $nLfdEvent);
}
if (!in_array($row['nlfdevent'], $this->aGeprueft)) {
$this->getEventZusammenhang($row['nlfdevent']);
}
}
}
private function getHeightFromEvent($nEnde, $nTop) {
$aPos = explode('.', (string) $nEnde);
$nBottom = $aPos[0]*$this->nZeilenHoehe*$this->nAnzZeilenProStunde;
$nBottom = $nBottom + $aPos[1]*$this->nZeilenHoehe;
$nBottom = $nBottom - ($this->nDisplayStundenVon*$this->nZeilenHoehe*$this->nAnzZeilenProStunde);
$nHeight = $nBottom - $nTop;
return $nHeight;
}
public function updateEvent($nId, $aColumns) {
$sSql = " update event set ";
foreach ($aColumns as $key => $value) {
$sSql.= $key." = '".strip_tags($value)."', ";
}
$sSql.= " nlfdevent = ". intval($nId);
$sSql.= " where nlfdevent = ".intval($nId);
mysql_query($sSql);
}
public function removeEvent($nId) {
$sSql = "delete from event
where nlfdevent = ".intval($nId);
mysql_query($sSql);
}
public function addEvent($sBez, $sBesch, $dtVon, $dtBis, $sColor) {
if ($dtVon<$dtBis && substr($dtVon,0,10) == substr($dtBis,0,10)) {
$sSql = "insert into event (
seventbez,
seventbeschreibung,
dtvon,
dtbis,
scolor
) values (
'".strip_tags($sBez)."',
'".strip_tags($sBesch)."',
'".strip_tags($dtVon)."',
'".strip_tags($dtBis)."',
'".strip_tags($sColor)."'
)";
mysql_query($sSql);
}
return mysql_insert_id();
}
public function getEventDetails($nId) {
$sSql = " select nlfdevent,
seventbez,
UNIX_TIMESTAMP(dtvon) dtvontimestamp,
date_format( dtvon, '%H:%i' ) dtvon,
date_format( dtvon, '%Y-%m-%d' ) datum,
date_format( dtvon, '%Y%m%d' ) stagvon,
date_format( dtvon, '%H%i' ) suhrzeitvon,
date_format( dtbis, '%H:%i' ) dtbis,
date_format( dtbis, '%Y%m%d' ) stagbis,
date_format( dtbis, '%H%i' ) suhrzeitbis,
date_format( dtvon, '%d' ) tag,
date_format( dtvon, '%m' ) monat,
date_format( dtvon, '%Y' ) jahr,
scolor
from event
where nlfdevent = ".$nId." ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$aEvent = array();
$aEvent['id'] = $row['nlfdevent'];
$aEvent['datum'] = $row['datum'];
$aEvent['tag'] = $row['tag'];
$aEvent['monat'] = $row['monat'];
$aEvent['jahr'] = $row['jahr'];
$aEvent['dtDatum'] = $row['stagvon'];
$aEvent['dtStart'] = $row['suhrzeitvon'];
$aEvent['dtEnde'] = $row['suhrzeitbis'];
$aEvent['sColor'] = $row['scolor'];
$aEvent['dtVon'] = $row['dtvon'];
$aEvent['dtBis'] = $row['dtbis'];
$aEvent['bez'] = $row['seventbez'];
$aEvent['timest'] = $row['dtvontimestamp'];
}
mysql_free_result($result);
return $aEvent;
}
private function getEvents() {
@mysql_query("delete from temp where nidentid = ".$this->sIdentNumber);
$sSql = " select nlfdevent,
seventbez,
UNIX_TIMESTAMP(dtvon) dtvontimestamp,
date_format( dtvon, '%H:%i' ) dtvon,
date_format( dtvon, '%Y%m%d' ) stagvon,
date_format( dtvon, '%H%i' ) suhrzeitvon,
date_format( dtbis, '%H:%i' ) dtbis,
date_format( dtbis, '%Y%m%d' ) stagbis,
date_format( dtbis, '%H%i' ) suhrzeitbis,
scolor
from event
where UNIX_TIMESTAMP(dtvon) >= ".$this->aTage[1]['timestamp']."
and UNIX_TIMESTAMP(dtbis) <= ".($this->aTage[$this->nTage]['timestamp']+(24*60*60))."
and date_format(dtvon, '%k') >= ".$this->nDisplayStundenVon."
and date_format(dtbis, '%k') <= ".($this->nDisplayStundenBis+1)."
and dtvon < dtbis
order by dtvon asc, (dtbis - dtvon) desc ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nIndex = $this->getIndexFromDay($row['stagvon']);
if (!is_array($this->aEvent[$nIndex])) {
$this->aEvent[$nIndex] = array();
}
$aEventAkt = array();
$aEventAkt['id'] = $row['nlfdevent'];
$aEventAkt['dtDatum'] = $row['stagvon'];
$aEventAkt['dtStart'] = $row['suhrzeitvon'];
$aEventAkt['dtEnde'] = $row['suhrzeitbis'];
$aEventAkt['nStart'] = $this->getZeile($aEventAkt['dtStart'], 0);
$aEventAkt['nEnde'] = $this->getZeile($aEventAkt['dtEnde'], 1);
$aEventAkt['nTop'] = $this->getTopPositionFromEvent($aEventAkt['nStart']);
$aEventAkt['nHeight'] = $this->getHeightFromEvent($aEventAkt['nEnde'], $aEventAkt['nTop']);
$aEventAkt['sColor'] = $row['scolor'];
$aEventAkt['dtVon'] = $row['dtvon'];
$aEventAkt['dtBis'] = $row['dtbis'];
$aEventAkt['bez'] = $row['seventbez'];
$aEventAkt['timest'] = $row['dtvontimestamp'];
array_push($this->aEvent[$nIndex], $aEventAkt);
}
mysql_free_result($result);
for ($t=1; $t<=$this->nTage; $t++) {
if (is_array($this->aEvent[$t])) {
for ($y=0; $y<count($this->aEvent[$t]); $y++) {
$aStart = explode('.', $this->aEvent[$t][$y]['nStart']);
$aEnde = explode('.', $this->aEvent[$t][$y]['nEnde']);
$nStart = $aStart[0].$aStart[1];
$nEnde = $aEnde[0].$aemde[1];
for ($i=$aStart[0]; $i<=$aEnde[0]; $i++) {
for ($x=1; $x<=$this->nAnzZeilenProStunde; $x++) {
$nPosAkt = $i.$x;
if (($x>=$aStart[1] && $i==$aStart[0]) || ($i<$aEnde[0] && $i!=$aStart[0]) || ($i==$aEnde[0] && $x<=$aEnde[1])) {
$nAktuell = ($i.str_pad($x, 5, '0', STR_PAD_LEFT));
$nMax = intval($aEnde[0].str_pad($aEnde[1], 5, '0', STR_PAD_LEFT));
$nMin = ($aStart[0].str_pad($aStart[1], 5, '0', STR_PAD_LEFT));
if (intval($nAktuell)>=intval ($nMin) && intval ($nAktuell)<= intval ($nMax)) {
$sSql = "insert into temp (
nidentid,
nlfdevent,
szelle,
nanzbelegt,
ndatum
) values (
'".$this->sIdentNumber."',
'".$this->aEvent[$t][$y]['id']."',
'".$i.".".$x."',
'0',
'".$this->aEvent[$t][$y]['dtDatum']."'
)";
@mysql_query($sSql);
}
}
}
}
}
}
}
$this->setSpaltenanzahl();
for ($t=1; $t<=$this->nTage; $t++) {
if (is_array($this->aEvent[$t])) {
for ($y=0; $y<count($this->aEvent[$t]); $y++) {
$sSql = "select distinct nanzspalten from temp where nlfdevent = ".$this->aEvent[$t][$y]['id'];
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nAnzspalten = $row['nanzspalten'];
$nWidth = floor(100 / $row['nanzspalten']);
}
mysql_free_result($result);
$sSql = NULL;
// Bau neues SQL für Pos zusammen
for ($i=1; $i<=$nAnzspalten; $i++) {
if ($i!=1) {
$sSql .= "union all ";
}
$sSql .= "(select count(*) nbelegt, ".$i." npos from temp where nidentid = ".$this->sIdentNumber." and szelle in (SELECT t1.* from (select szelle from temp where nlfdevent = ".$this->aEvent[$t][$y]['id'].") t1) and nposbelegt = ".$i." and ndatum = ".$this->aEvent[$t][$y]['dtDatum'].") ";
}
$sSql .= "order by 1,2 limit 1 ";
$result = mysql_query($sSql);
while ($row = mysql_fetch_assoc($result)) {
$nPos = $row['npos'];
$nLeft = ($nPos-1)*$nWidth;
}
@mysql_free_result($result);
$this->aEvent[$t][$y]['nWidth'] = $nWidth.'%';
$this->aEvent[$t][$y]['nLeft'] = $nLeft.'%';
$sSql = "update temp set nposbelegt = ".$nPos." where nlfdevent = ".$this->aEvent[$t][$y]['id'];
@mysql_query($sSql);
}
}
}
// Nochmal zur sicherheit alles ausm temp raus
@mysql_query("delete from temp where nidentid = ".$this->sIdentNumber);
return $this->aEvent;
}
public function fetchTable() {
echo "<table border='0' id='myTable' style='width:100%; margin-top:-2px;' style='overflow:hidden'>";
echo "<tbody id='myTableBody'>";
$this->fetchEvents();
// Berechenen der Breite von den Spalten (prozentual)
$num_prozent = 100 / $this->nTage;
// Schleife für gesamten Stunden
for ($i=$this->nDisplayStundenVon; $i<=$this->nDisplayStundenBis; $i++) {
// Schleife für die Zeilen einer Stunde - Standart sind 2, können aber über Funktion verändert werden
for ($x=1; $x<=$this->nAnzZeilenProStunde; $x++) {
echo "<tr>";
if ($x==1) {
echo "<td unselectable='on' rowspan='".$this->nAnzZeilenProStunde."' ".($i==$this->nDisplayStundenVon?' id=\'CalendarZelle0\'':"")." class='tableDateCell' style=' -moz-user-select: none; ";
if ($i==$this->nDisplayStundenBis) {
echo " border-bottom:0px; ";
}
echo "'> ";
echo "<div unselectable='on'>";
echo $i."<span>00</span>";
echo "</div>";
echo "</td>";
}
// Schleife für die Zeilen der Tage (Spalten)
for ($y=1; $y<=$this->nTage; $y++) {
echo "<td class='";
// Leider wichtig für die Unterschiedlichen Rahmen
if ($x==1 && $this->nAnzZeilenProStunde==1) {
echo "tableDataCell_dunkel_dunkel";
}
elseif ($x==1 && $this->nAnzZeilenProStunde>1) {
echo "tableDataCell_dunkel_hell";
}
elseif ($x==$this->nAnzZeilenProStunde) {
echo "tableDataCell_hell_dunkel";
}
else {
echo "tableDataCell_hell_hell";
}
echo "' style='padding:0px; width:".$num_prozent."%; height:".$this->nZeilenHoehe."px; vertical-align:top; -moz-user-select: none; ";
// Wenn letzter Tag, keinen rechten Rahmen zeigen
if ($y==$this->nTage) {
echo "border-right: 0px;";
}
if ($i==$this->nDisplayStundenBis && $x==$this->nAnzZeilenProStunde) {
echo "border-bottom: 0px;";
}
// Wenn Arbeitszeit angezeigt werden soll, dann andere Hintergrundfarbe
if ($this->bDisplayArbeitszeit==true) {
if ($i>=$this->nArbeitszeitVon && $i<$this->nArbeitszeitBis && in_array($this->aTage[$y]['kuerzel'], $this->aArbeitsTage)) {
echo "background-color:#ffffd5";
}
}
echo "'";
// ID´s in erster Zeile setzen, damit später mit Javascript der Header Richtig gesetzt werden kann
if ($i==$this->nDisplayStundenVon && $x==1) {
echo " id='CalendarZelle".$y."'";
}
$sId = str_pad($y, 4, "0", STR_PAD_LEFT).'.'.str_pad($i, 4, "0", STR_PAD_LEFT).'.'.str_pad($x, 4, "0", STR_PAD_LEFT);
echo " unselectable='on' ><div id='".$sId."' onmousedown='newEvent(this);' unselectable='on' style='-moz-user-select: none; /*background-color:#3399ff;*/ width:100%; height:".($this->nZeilenHoehe-1)."px; margin:0px; padding:0px; font-size:1px;'></div></td>";
}
echo "</tr>";
}
}
echo "</tbody>";
echo "</table>";
}
public function fetchEvents() {
echo "<tr style='height:0px;' id='eventContainer'>";
echo "<td style='padding:0px; height:0px; maring:0px; border: 0px solid #a0a0a0'>";
echo "</td>";
// Events holen
$aEvent = $this->getEvents();
for ($i=1; $i<=$this->nTage; $i++) {
echo "<td style='padding:0px; height:0px; maring:0px; border: 0px solid #a0a0a0'>";
echo "<div style='display: block; margin-right: 5px; position: relative; height: 1px; font-size: 0px; line-height: 1.2; margin-top: 0px;' id='eventTag".$i."'>";
if (is_array($this->aEvent[$i])) {
for ($y=0; $y<count($aEvent[$i]); $y++) {
echo " <div class='termin' ondblclick='alert(\"Jetzt Termin aendern: \"+".$aEvent[$i][$y]['id'].")' id='event_".$aEvent[$i][$y]['id']."' unselectable='on' style='overflow: hidden; -moz-user-select: none; position: absolute; top:".($aEvent[$i][$y]['nTop']+1)."px; font-family: Tahoma; font-size: 8pt; color: rgb(0, 0, 0); left: ".$aEvent[$i][$y]['nLeft']."; width: ".$aEvent[$i][$y]['nWidth']."; height: ".($aEvent[$i][$y]['nHeight']+1)."px; background-color: rgb(0, 0, 0);' onmousedown='dragstart(this)' onmouseover='overstart(this)' onmouseout='overend()'>";
echo " <div unselectable='on' style='position: absolute; width: 100%; text-align: right;'><img id='eventRemove_".$aEvent[$i][$y]['id']."' onmouseover='$(\"event_".$aEvent[$i][$y]['id']."\").onmousedown = function() {null;}' onmouseout='$(\"event_".$aEvent[$i][$y]['id']."\").onmousedown = function() {dragstart(this);}' onclick='removeEvent(this.id.substr(12).toString())' src='img/del.gif' style='margin-right: 2px; margin-top: 2px; cursor: pointer;' width='10' height='10'></div>";
echo " <div unselectable='on' style='height: 1px; line-height: 1px; font-size: 0px; width: 1px;'><!-- --></div>";
echo " <div id='eventContent_".$aEvent[$i][$y]['id']."' class='event' style=' border-right: 1px solid rgb(0, 0, 0); overflow: hidden; margin-top: 0px; height: ".($aEvent[$i][$y]['nHeight']-1)."px; background-color: rgb(255, 255, 255);' unselectable='on'>";
echo " <div id='eventColor_".$aEvent[$i][$y]['id']."' style='position: absolute; left: 0px; width: 5px; height: ".($aEvent[$i][$y]['nHeight']-1)."px; background-color: #".$aEvent[$i][$y]['sColor']."; font-size: 1px;' unselectable='on'></div>";
echo " <div style='position: absolute; left: 5px; top: 0px; width: 1px; background-color: rgb(0, 0, 0); height: 100%;' unselectable='on'></div>";
echo " <div unselectable='on' style='padding-left: 8px;'>".$aEvent[$i][$y]['bez']." (".$aEvent[$i][$y]['dtVon']." - ".$aEvent[$i][$y]['dtBis'].")</div>";
echo " </div>";
echo " </div>";
}
}
echo "</div>";
echo "</td>";
}
echo "</tr>";
}
public function fetchTableHeader() {
echo "<tr>";
echo "<td id='calendarHeaderZelle0'> </td>";
for ($y=1; $y<=$this->nTage; $y++) {
echo "<td unselectable='on' id='calendarHeaderZelle".$y."' style='overflow:hidden; -moz-user-select: none; '>";
echo "<div unselectable='on' style='padding-bottom:3px;padding-top:3px;overflow:hidden; white-space:nowrap; -moz-user-select: none; '>";
echo $this->aTage[$y]['bez'].", ";
echo "<br />";
echo "<span style='font-weight:normal;'>".$this->aTage[$y]['formatiert']."</span>";
echo "</div>";
echo "</td>";
}
echo "<td id='calendarHeaderZelleSpacer' ".($this->nCalendarHoehe==false?'':'style=\'width:16px;\'')."></td>";
echo "</tr>";
}
public function getNewEventLayer($nMode, $sBetreff, $sText, $sFarbe, $dtDatum, $dtVon, $dtBis) {
echo "<form method='get' action='".$PHP_SELF."'>";
if ($nMode==1) {
echo "<input type='hidden' name='terminAdd' value='true'>";
echo "<input type='hidden' name='aktion' value='newTermin'>";
} else {
echo "<input type='hidden' name='terminUpdate' value='true'>";
}
echo "<table style='width:100%;' id='newEventLayer'>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Titel: </td>
<td colspan='2'><input type='text' name='sBetreff' style='width:100%' value='".$sBetreff."'></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Kleur: </td>
<td><input type='text' name='sFarbe' readonly id='sFarbe' value='".($sFarbe==''?'0000ff':$sFarbe)."' style='width:85px'></td>
<td>
<div onclick='document.getElementById(\"sFarbe\").value=\"0000ff\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#0000ff'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"800080\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#800080'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"ffffff\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#ffffff'> </div>
<div onclick='document.getElementById(\"sFarbe\").value=\"ff0000\"' style='width:20px; float:left; height:20px; margin-right:8px; cursor:pointer; border:1px solid #A0A0A0; background-color:#ff0000'> </div>
</td
</tr>
<tr>
<td colspan='3'><hr rules='all'></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Van: </td>
<td><input type='text' name='dtDatum' value='".$dtDatum."' style='width:85px'></td>
<td> Om: <input type='text' name='dtVon' value='".$dtVon."' style='width:50px'> Uur</td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Tot: </td>
<td style='width:1%'> </td>
<td style='width:98%'> Om: <input type='text' name='dtBis' value='".$dtBis."' style='width:50px'> Uur</td>
</tr>
<tr>
<td colspan='3'><hr></td>
</tr>
<tr>
<td style='width:1%; white-space: nowrap; vertical-align:top;'>Beschrijving: </td>
<td colspan='2'><textarea style='width:100%;' name='sBetreff' rows='5'>".$sText."</textarea></td>
</tr>
<tr>
<td colspan='3'><hr></td>
</tr>
<tr>
<td colspan='3' style='text-align:right;'><input type='submit' value='Plaatsen'/></td>
</tr>
</table>
</form>";
}
public function init() {
echo "<table style='width:".($this->nCalendarBreite)."' class='CalendarTableHeader' id='CalendarTableHeader'>";
echo "<tbody id='myTableHeader'>";
$this->fetchTableHeader();
echo "</tbody>";
echo "</table>";
echo "<div id='layer'><img src='img/loader.gif'></div>";
echo "<div id='CalendarTableBody' style='margin:0px; margin-top:-1px; padding:0px; overflow:auto; width:".$this->nCalendarBreite."; border-right: 1px solid #a0a0a0; border-bottom: 1px solid #a0a0a0; border-top: 1px solid #a0a0a0; ".($this->nCalendarHoehe!=false?'height:'.$this->nCalendarHoehe.'px;':'')."' >";
$this->fetchTable();
echo "</div>";
echo "<script>";
echo "
var nZelleHeight = ".$this->nZeilenHoehe.";
var nZelleWidth = $('CalendarZelle1').offsetWidth;
function setSize() {
var nSpacer = 0;
for (i=0; i<".$this->nTage."; i++) {
objHeaderZelle = $('calendarHeaderZelle'+i);
if (i!=0)
objDataZelle = $('CalendarZelle1');
else
objDataZelle = $('CalendarZelle0');
nSpacer = nSpacer + objDataZelle.offsetWidth-1;
objHeaderZelle.style.width = objDataZelle.offsetWidth-1;
}
$('CalendarTableHeader').style.width = $('CalendarTableBody').offsetWidth;
}
addLoadEvent(function() {
setSize();
nZelleWidth = $('CalendarZelle1').offsetWidth;
draginit();
objBody = document.getElementsByTagName('body')[0];
nAnzZeilenProStunde = ".intval($this->nAnzZeilenProStunde).";
nZeilenHoehe = ".intval($this->nZeilenHoehe).";
nMode = ".intval($this->nMode).";
nTage = ".intval($this->nTage).";
nKW = ".intval($this->nKW).";
nJahr = ".intval($this->nJahr).";
nDisplayStundenVon = ".intval($this->nDisplayStundenVon).";
nDisplayStundenBis = ".intval($this->nDisplayStundenBis).";
nTopGrid = getOffsetTop($('CalendarZelle1'));
});
addResizeEvent(function() {
setSize();
nZelleWidth = $('CalendarZelle1').offsetWidth;
});
";
echo "</script>";
}
}
?>
ik denk niet dat er hier iemand is die 710 regels code wil gaan doorspitten. plaats alleen relevante code of als je zulke grote code wil posten doe dit dan ergens zoals bij plaatscode.be en verwijs hiernaar d.m.v. een link dat houd je topic overzichtelijk.
verder raad ik je aan om het stukje waarbij je op volgende/vorige klikt even op te zoeken en het stukje waarbij bepaalt wordt hoeveel naar voren/terug. dan zie je meestal vanzelf waar de fout zit.
Quote:
private function getFirstDayOfWeek($year, $weeknr) {
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'weeks', $monday);
}
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'weeks', $monday);
}
Naar
Quote:
private function getFirstDayOfWeek($year, $weeknr) {
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'days', $monday);
}
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
return strtotime('+' . ($weeknr - 1) . 'days', $monday);
}
dan krijg je wel de dagen achter elkaar, maar dan begint hij bij 16/01/2012