Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="calender">
- <div class='month_name' style='background-color:#9d61bf; color:#ffffff;'>
- <?php echo 'Oct'//month_de($thisMonth); ?></div>
- <div class='day_box'>Mo</div>
- <div class='day_box'>Di</div>
- <div class='day_box'>Mi</div>
- <div class='day_box'>Do</div>
- <div class='day_box'>Fr</div>
- <div class='day_box' style='color:#b51b1e;'>Sa</div>
- <div class='day_box' style='color:#b51b1e;'>So</div>
- <?php
- //$daten = get_Kalenderdaten("kalenderdaten");
- //$daten = file_get_contents("cal.txt");
- //$content = preg_split('/;/',$daten);
- // you should just use file() to read the lines of the file
- // cal2.txt is my test file with dates in YYYY-MM-DD format and no ; on the end of each line
- $content = file('cal2.txt',FILE_IGNORE_NEW_LINES);
- // loop over the data once, building an array with the date ranges expanded
- // the entries in the data array are -
- // BS (booking start), B (booked), BE (booking end), SS (closed start), S (closed), SE (closed end)
- $data = [];
- foreach($content as $row)
- {
- // use explode() for simple cases
- list($typ, $beginn, $ende) = explode(',',$row);
- // produce the date range
- $begin = new DateTime($beginn);
- $end = new DateTime($ende);
- // include the end date in the interval
- $end = $end->modify('+1 day');
- $interval = DateInterval::createFromDateString('1 day');
- $period = new DatePeriod($begin, $interval, $end);
- // loop over the date range
- foreach($period as $dt)
- {
- $date = $dt->format("Y-m-d");
- $extra = '';
- // start
- if($date == $beginn) $extra = 'S';
- // end
- if($date == $ende) $extra = 'E';
- $data[$date][] = $typ.$extra;
- }
- }
- // loop to produce the output
- foreach(range(1,$thisMonthLastDay) as $d)
- {
- // day name
- $tag_eng = date('D', mktime(0,0,0,date("m"),$d,date('Y')));
- // current date
- $datum = date('Y-m-d', mktime(0,0,0,date("m"),$d,date('Y')));
- $colvar ="";
- // determine the combined value for the current date
- $val = implode('-',$data[$datum]??[]);
- // map the value to the $colvar value
- switch($val)
- {
- case 'BS':
- $colvar = " box-bg-wr";
- break;
- case 'B':
- $colvar = " box-bg-r";
- break;
- case 'BE':
- $colvar = " box-bg-rw";
- break;
- case 'SS':
- $colvar = " box-bg-wg";
- break;
- case 'S':
- $colvar = " box-bg-g";
- break;
- case 'SE':
- $colvar = " box-bg-gw";
- break;
- case 'BE-SS':
- $colvar = " box-bg-rwg";
- break;
- case 'SE-BS':
- $colvar = " box-bg-gwr";
- break;
- case 'SE-SS':
- $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"
- break;
- case 'BE-BS':
- $colvar = " box-bg-rwr";
- break;
- }
- $col = columnStart($tag_eng);
- echo "<div class='day_box{$colvar}' id='$datum'
- style='grid-column-start:$col;'>$d</div>\n";
- }
- ?>
- <div style="position: relative; left: -120px; top: 40px; font-size: 1rem;">
- <div class='day_box' style='background-color: #f17571; color: #ffffff; width: 15px;
- height: 15px;'></div><span style="position: relative; bottom: 22px; left: 20px;">
- reserviert</span>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement