Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2024
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. <div class="calender">
  2. <div class='month_name' style='background-color:#9d61bf; color:#ffffff;'>
  3. <?php echo 'Oct'//month_de($thisMonth); ?></div>
  4. <div class='day_box'>Mo</div>
  5. <div class='day_box'>Di</div>
  6. <div class='day_box'>Mi</div>
  7. <div class='day_box'>Do</div>
  8. <div class='day_box'>Fr</div>
  9. <div class='day_box' style='color:#b51b1e;'>Sa</div>
  10. <div class='day_box' style='color:#b51b1e;'>So</div>
  11. <?php
  12.  
  13. //$daten = get_Kalenderdaten("kalenderdaten");
  14. //$daten = file_get_contents("cal.txt");
  15. //$content = preg_split('/;/',$daten);
  16.  
  17. // you should just use file() to read the lines of the file
  18.  
  19. // cal2.txt is my test file with dates in YYYY-MM-DD format and no ; on the end of each line
  20. $content = file('cal2.txt',FILE_IGNORE_NEW_LINES);
  21.  
  22. // loop over the data once, building an array with the date ranges expanded
  23. // the entries in the data array are -
  24. // BS (booking start), B (booked), BE (booking end), SS (closed start), S (closed), SE (closed end)
  25. $data = [];
  26. foreach($content as $row)
  27. {
  28. // use explode() for simple cases
  29. list($typ, $beginn, $ende) = explode(',',$row);
  30.  
  31. // produce the date range
  32. $begin = new DateTime($beginn);
  33. $end = new DateTime($ende);
  34. // include the end date in the interval
  35. $end = $end->modify('+1 day');
  36. $interval = DateInterval::createFromDateString('1 day');
  37. $period = new DatePeriod($begin, $interval, $end);
  38.  
  39. // loop over the date range
  40. foreach($period as $dt)
  41. {
  42. $date = $dt->format("Y-m-d");
  43. $extra = '';
  44. // start
  45. if($date == $beginn) $extra = 'S';
  46. // end
  47. if($date == $ende) $extra = 'E';
  48. $data[$date][] = $typ.$extra;
  49. }
  50. }
  51.  
  52. // loop to produce the output
  53. foreach(range(1,$thisMonthLastDay) as $d)
  54. {
  55. // day name
  56. $tag_eng = date('D', mktime(0,0,0,date("m"),$d,date('Y')));
  57. // current date
  58. $datum = date('Y-m-d', mktime(0,0,0,date("m"),$d,date('Y')));
  59. $colvar ="";
  60.  
  61. // determine the combined value for the current date
  62. $val = implode('-',$data[$datum]??[]);
  63.  
  64. // map the value to the $colvar value
  65. switch($val)
  66. {
  67. case 'BS':
  68. $colvar = " box-bg-wr";
  69. break;
  70. case 'B':
  71. $colvar = " box-bg-r";
  72. break;
  73. case 'BE':
  74. $colvar = " box-bg-rw";
  75. break;
  76.  
  77. case 'SS':
  78. $colvar = " box-bg-wg";
  79. break;
  80. case 'S':
  81. $colvar = " box-bg-g";
  82. break;
  83. case 'SE':
  84. $colvar = " box-bg-gw";
  85. break;
  86.  
  87. case 'BE-SS':
  88. $colvar = " box-bg-rwg";
  89. break;
  90. case 'SE-BS':
  91. $colvar = " box-bg-gwr";
  92. break;
  93.  
  94. case 'SE-SS':
  95. $colvar = " box-bg-g"; // the OP's logic produces " box-bg-wg" for this case, based on the SS match, and never reaches the Schließung Ende und Start am selben Tag logic to produce the " box-bg-g"
  96. break;
  97.  
  98. case 'BE-BS':
  99. $colvar = " box-bg-rwr";
  100. break;
  101. }
  102.  
  103. $col = columnStart($tag_eng);
  104. echo "<div class='day_box{$colvar}' id='$datum'
  105. style='grid-column-start:$col;'>$d</div>\n";
  106. }
  107. ?>
  108. <div style="position: relative; left: -120px; top: 40px; font-size: 1rem;">
  109. <div class='day_box' style='background-color: #f17571; color: #ffffff; width: 15px;
  110. height: 15px;'></div><span style="position: relative; bottom: 22px; left: 20px;">
  111. reserviert</span>
  112. </div>
  113. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement