カレンダ機能を追加する
Revision | fad83be2bc84af7df519aa4ff3fbc6aa6911ecc7 (tree) |
---|---|
Time | 2017-07-09 18:06:21 |
Author | stingll <jostingll@gmai...> |
Commiter | stingll |
3ヶ月毎に通常のカレンダ表示をする処理を追加(祭日等の自動計算ははいっていない)
@@ -1,13 +1,12 @@ | ||
1 | 1 | <?php |
2 | -# Mantis - a php based bugtracking system | |
3 | - | |
4 | -# $Id: | |
5 | 2 | # -------------------------------------------------------- |
6 | -?> | |
3 | +# Personal Calendar Displays 2017-07-09 | |
4 | +# | |
5 | +# -------------------------------------------------------- | |
7 | 6 | |
8 | -<?php | |
9 | 7 | |
10 | -function html_calendar( $syear, $sday, $befp, $aftp, $kenpl, $cntpl ) { | |
8 | +function html_calendar( $syear = NULL , $sday = NULL , $peri == NULL, $befp = NULL , $aftp = NULL , $kenpl = NULL , $cntpl = NULL ) { | |
9 | + | |
11 | 10 | $basetm = 90000; // この値を利用して表示時間間隔を求める |
12 | 11 | // html rawspan 設定値 |
13 | 12 | $peri = 100; // 1時間刻みの場合「25」(3600s)。30分刻みなら「50」(1800s)、15分刻みなら「100」(900s)) |
@@ -248,6 +247,190 @@ function html_calendar( $syear, $sday, $befp, $aftp, $kenpl, $cntpl ) { | ||
248 | 247 | // echo '</html>'; |
249 | 248 | |
250 | 249 | } |
251 | -?> | |
252 | - | |
250 | + | |
251 | + | |
252 | +function drawCalender( $y ,$m ) { | |
253 | + $cnstrust = array(); | |
254 | + | |
255 | + $t = mktime(0, 0, 0, $m, 1, $y); //$y年$m月1日のUNIXTIME | |
256 | + $w = date('w', $t); //1日の曜日(0:日~6:土) | |
257 | + $n = date('t', $t); //$y年$m月の日数 | |
258 | + print '<table border="1" bgcolor="FFFFFF">'."\n"; | |
259 | + print "<caption><font color=\"#0000FF\"><b>{$y}年{$m}月</font></b></caption>\n"; | |
260 | + print <<<DAY_TITLE | |
261 | + <tr> | |
262 | + <th>日</th> | |
263 | + <th>月</th> | |
264 | + <th>火</th> | |
265 | + <th>水</th> | |
266 | + <th>木</th> | |
267 | + <th>金</th> | |
268 | + <th>土</th> | |
269 | + </tr> | |
270 | + <tr> | |
271 | +DAY_TITLE; | |
272 | + for( $i = 1 - $w ; $i <= $n + 7 ; $i++ ){ | |
273 | + print "<br>\n"; | |
274 | + if ( ( ( $i + $w ) % 7 ) == 1 ) { | |
275 | + print "<tr>\n"; | |
276 | + } | |
277 | + if ( ( 0 < $i ) && ( $i <= $n ) ) { | |
278 | +// $tindx = date("Y-m-d H:i",mktime($m, $i, 0, $m, $i, $y)); //$y年$m月1日のUNIXTIME | |
279 | + $tindx1 = mktime($i, $i, $i, $m, $i, $y); //$y年$m月1日のUNIXTIME | |
280 | +// print "00:tindx1(UNIX) : ".$tindx1."<br>"; | |
281 | + $tmval = _dateByMinutes('floor', $tindx1, 15); | |
282 | +// $tmval = _dateByHours('floor', $tindx1, 24); | |
283 | + $cnstrust[$tmval] .= $tindx1 . " ; "; | |
284 | +// print "01:tmval, cnstrust[tmval]:<br>".$tmval.", ".$cnstrust[$tmval]."<br>"; | |
285 | + // print "<td align=\"center\">$i</td>\n"; | |
286 | + } else { | |
287 | + print "<td> </td>\n"; | |
288 | + } | |
289 | + if ( ( ( $i + $w ) % 7 ) == 0 ) { | |
290 | + print "</tr>\n"; | |
291 | + if ( $i >= $n ) { | |
292 | + break; | |
293 | + } | |
294 | + } | |
295 | +// $cnstrust[$tmval] .= "<br>"; | |
296 | + } | |
297 | + print "</table>\n"; | |
298 | +} | |
299 | + | |
300 | + | |
301 | +/* | |
302 | + * dateByMinutes | |
303 | + * @assert Unix Time 1489133280=("2017-03-10 17:08") == "2017-03-10 17:00" | |
304 | + * @assert Unix Time 1489133580=("2017-03-10 17:13") == "2017-03-10 17:00" | |
305 | + * @assert Unix Time("2017-03-10 17:23") == "2017-03-10 17:15" | |
306 | + * @assert Unix Time("2017-03-10 17:33") == "2017-03-10 17:30" | |
307 | + * @assert Unix Time("2017-03-10 17:43") == "2017-03-10 17:30" | |
308 | + * @assert Unix Time("2017-03-10 17:49") == "2017-03-10 17:45" | |
309 | + * @assert Unix Time("2017-03-10 17:54") == "2017-03-10 17:45" | |
310 | + * | |
311 | + * @assert Unix Time("2017-03-10 17:14") == "2017-03-10 17:00" | |
312 | + * @assert Unix Time("2017-03-10 17:54") == "2017-03-10 17:30" | |
313 | + */ | |
314 | + | |
315 | +// tperi = 15 or 30 or <= 60 | |
316 | +function _dateByMinutes($mode = 'floor',$tmpi = NULL, $tperi = 60) { | |
317 | + print "1: tmpi, tperi: ".$tmpi.",date( ".date("Y-m-d H:i:s",$tmpi)." ), ".$tperi."<br>"; | |
318 | + if (is_null($tmpi)) { | |
319 | + $tmpi = time(); | |
320 | + } | |
321 | + $nen = date("Y",$tmpi); | |
322 | + $gan = date("m",$tmpi); | |
323 | + $dan = date("d",$tmpi); | |
324 | + | |
325 | +// print "2: tmpi, nen, gan, dan: ".$tmpi.", ".$nen.", ".$gan.",".$dan."<br>"; | |
326 | + if ($mode == 'ceil') { | |
327 | + $minute = sprintf("%02s", ceil(date('i',$tmpi) / $tperi) * $tperi); | |
328 | +// print "2.5c: minutes, nen, gan, dan: ".$minute.", ".$nen.", ".$gan.",".$dan."<br>"; | |
329 | + } else { | |
330 | + $minute = sprintf("%02s", floor(date('i',$tmpi) / $tperi) * $tperi); | |
331 | +// print "2.5f: minutes, nen, gan, dan: ".$minute.", ".$nen.", ".$gan.",".$dan."<br>"; | |
332 | + } | |
333 | + $time_string = date("Y-m-d H:i", mktime(date('H',$tmpi), $minute, 0, $gan, $dan, $nen)); | |
334 | +// print "3: tmpi time_string: ".$tmpi.", ".$time_string."<br>"; | |
335 | + return $time_string; | |
336 | +} | |
337 | + | |
338 | + | |
339 | +// tperi = 12 or 24 | |
340 | +function _dateByHours($mode = 'floor',$tmpi = NULL, $tperi = 12) { | |
341 | + if (is_null($tmpi)) { | |
342 | + $tmpi = time(); // 現在時刻のUixTimeを取得 | |
343 | + } | |
344 | +// print "01: tmpi, tperi: ".$tmpi."date( ".date("Y-m-d H:i",$tmpi)." ), ".$tperi."<br>"; | |
345 | + $nen = date("Y",$tmpi); | |
346 | + $gan = date("m",$tmpi); | |
347 | + $dan = date("d",$tmpi); | |
348 | + | |
349 | +// print "02: tmpi, nen, gan, dan: ".$tmpi.", ".$nen.", ".$gan.",".$dan."<br>"; | |
350 | + if ($mode == 'ceil') { | |
351 | + $hour = sprintf("%02s", ceil(date('H',$tmpi) / $tperi) * $tperi); | |
352 | +// print "02.5c: minutes, nen, gan, dan: ".$minute.", ".$nen.", ".$gan.",".$dan."<br>"; | |
353 | + } else { | |
354 | + $hour = sprintf("%02s", floor(date('H',$tmpi) / $tperi) * $tperi); | |
355 | +// print "02.5f: minutes, nen, gan, dan: ".$minute.", ".$nen.", ".$gan.",".$dan."<br>"; | |
356 | + } | |
357 | + $time_string = date("Y-m-d H:i", mktime($hour, 0, 0, $gan, $dan, $nen)); | |
358 | +// print "03: tmpi time_string: ".$tmpi.", ".$time_string."<br>"; | |
359 | + return $time_string; | |
360 | +} | |
361 | + | |
362 | + | |
363 | + | |
364 | + | |
365 | + | |
366 | +<?php | |
367 | +function ordinary_calendar_main($s_year) { | |
368 | + | |
369 | + print "<html>"; | |
370 | + print "<head>"; | |
371 | + print "<meta charset='utf-8'>"; | |
372 | + print "<title>PHPカレンダサンプル</title>"; | |
373 | + | |
253 | 374 | |
375 | + print " <center>"; | |
376 | + print " <table width = "80%">"; | |
377 | + if ( is_null($s_year) ){ | |
378 | + $s_year = date("Y"); | |
379 | + } | |
380 | + for ( $i=1 ; $i<=12 ; $i++ ) { | |
381 | + if ( ( $i % 3 ) == 1 ) { | |
382 | + print "<tr>\n"; | |
383 | + } | |
384 | + print "<td>\n"; | |
385 | + drawCalender($yy,$i); | |
386 | + print "</td>\n"; | |
387 | + if ( ( $i % 3 ) == 0 ) { | |
388 | + print "</tr>\n"; | |
389 | + } | |
390 | + } | |
391 | +} | |
392 | + | |
393 | +function drawCalender( $y ,$m ) { | |
394 | + $cnstrust = array(); | |
395 | + | |
396 | + $t = mktime(0, 0, 0, $m, 1, $y); //$y年$m月1日のUNIXTIME | |
397 | + $w = date('w', $t); //1日の曜日(0:日~6:土) | |
398 | + $n = date('t', $t); //$y年$m月の日数 | |
399 | + print '<table border="1" bgcolor="FFFFFF">'."\n"; | |
400 | + print "<caption><font color=\"#0000FF\"><b>{$y}年{$m}月</font></b></caption>\n"; | |
401 | + print <<<DAY_TITLE | |
402 | + <tr> | |
403 | + <th>日</th> | |
404 | + <th>月</th> | |
405 | + <th>火</th> | |
406 | + <th>水</th> | |
407 | + <th>木</th> | |
408 | + <th>金</th> | |
409 | + <th>土</th> | |
410 | + </tr> | |
411 | + <tr> | |
412 | + DAY_TITLE; | |
413 | + for( $i = 1 - $w ; $i <= $n + 7 ; $i++ ){ | |
414 | + print "<br>\n"; | |
415 | + if ( ( ( $i + $w ) % 7 ) == 1 ) { | |
416 | + print "<tr>\n"; | |
417 | + } | |
418 | + if ( ( 0 < $i ) && ( $i <= $n ) ) { | |
419 | + $tindx1 = mktime($i, $i, $i, $m, $i, $y); //$y年$m月1日のUNIXTIME | |
420 | + $tmval = _dateByMinutes('floor', $tindx1, 15); | |
421 | + $cnstrust[$tmval] .= $tindx1 . " ; "; | |
422 | + print "<td align=\"center\">$i</td>\n"; | |
423 | + } else { | |
424 | + print "<td> </td>\n"; | |
425 | + } | |
426 | + if ( ( ( $i + $w ) % 7 ) == 0 ) { | |
427 | + print "</tr>\n"; | |
428 | + if ( $i >= $n ) { | |
429 | + break; | |
430 | + } | |
431 | + } | |
432 | + } | |
433 | + print "</table>\n"; | |
434 | +} | |
435 | + | |
436 | +?> |