Roy Barten Posted February 17, 2009 Share Posted February 17, 2009 okay, I thought it's time for another question. I have a HTML template that builds a calendar, it looks like the following: <html> <head> <title>Calendar Montly View</title> <link rel="stylesheet" href="style.css" type="text/css" /> </head> <body> <center> <table width="100%" class="tblcalendar" cellpadding="0" cellspacing="0"> <tr> <td colspan="7" class="tblheader"> <img src="calendar-previous.gif"> <img src="calendar-next.gif">   {month} {year}</td> </tr> <tr> <td class="tbldays">Monday</td> <td class="tbldays">Tuesday</td> <td class="tbldays">Wednesday</td> <td class="tbldays">Thurday</td> <td class="tbldays">Friday</td> <td class="tbldays">Saturday</td> <td class="tbldays">Sunday</td> </tr> [bLOCK calendar_week] <tr> [bLOCK calendar_day] <td> <table cellpadding="0" cellspacing="0"> <tr> <td class="dayheader">{day}</td> </tr> <tr> <td class="{class}"> </td> </tr> </table> </td> [END calendar_day] </tr> [END calendar_week] </table> </center> </body> </html> And i have some PHP code that use this code. This code looks like this: public function __construct($day, $month, $year){//functie aanmaken if(validateInput::onlyDigits($day) && validateInput::onlyDigits($month) && validateInput::onlyDigits($year)){//gegevens in de opgegeven variabele valideren en checken op eventuele fouten if($month >= 0 && $month <= 12){ self::$cmonthdays = date("t", mktime(0,0,0,$month, 1, $year));//$cmonthdays = aantal dagen in de maand if($day >= 0 && $day <= self::$cmonthdays) {//als $day hoger is dan 0 en lager dan het aantal dagen in de maand self::$cday = $day; self::$cmonth = $month;//variabele vullen self::$cyear = $year; } else {//anders foutmeldingen weergeven returnOutput::outputError("Calendar error: Invalid date set"); } } else { returnOutput::outputError("Calendar error: Invalid date set"); } } else { returnOutput::outputError("Calendar error: Invalid date set"); } } function calendarvMonth($start_week_on_monday = true){ if($start_week_on_monday === true) { } self::$cmontharray = "";//variabele comontharray = leeg $x = 0;//variabele x = 0 for ($i = 1; $i <= self::$cmonthdays; $i++)//$i=1 en zolang die lager is als $cmonthdays de onderstaande code uitvoeren en 1 optellen bij $i { if ($start_week_on_monday === true)//als de week op maandag begind { if (datentime::selectDayOfWeek($i, self::$cmonth, self::$cyear) == 0) self::$cmontharray[$x][6] = $i;//als de uitkomst van de functie selectday of week gelijk is aan 0 else self::$cmontharray[$x][datentime::selectDayOfWeek($i, self::$cmonth, self::$cyear)-1] = $i; if (datentime::selectDayOfWeek($i, self::$cmonth, self::$cyear) == 0) $x++; } else { self::$cmontharray[$x][datentime::selectDayOfWeek($i, self::cmonth, self::cyear)] = $i; if (datentime::selectDayOfWeek($i, self::$cmonth, self::$cyear) == 6) $x++; } } self::calendarDisplayMonth();//functie calendar displaymonth uitvoeren } function calendarDisplayMonth(){ $html = new Template(self::$mtemplate);//class template aanroepen $html->set("month", datentime::selectMonth("NL", self::$cmonth));//selecteer de huidige datum $html->set("year", self::$cyear);//selecteer huidige jaar foreach (self::$cmontharray as $key) { //voor elk item in de kalender $html->clear("calendar_day"); for($i = 0; $i < 7; $i++) { if(isset($key[$i])) { $html->set("day", $key[$i]); $html->set("class", "tblday"); } else { $html->set("day", " "); $html->set("class", "tblnoday"); } $html->parse("calendar_day"); } $html->parse("calendar_week"); } $html->parse(); $html->spit(); $calendartype = 2; self::calendarShowReservations($calendartype); } function calendarvDay($ndays){//functie declareren en $ndays kan ingevuld worden bij aanroepen functie if($ndays > 0 && $ndays <= 7) {//als $ndays hoger is dan 0 en lager of gelijk aan 7 $day = datentime::selectDayofWeek(self::$cday, self::$cmonth, self::$cyear);//$day = functie selectdayofweek aanroepen en waardes invullen met de variabele $cday cmonth en cyear if($ndays != 7) {//als ndays niet gelijk is aan 7 $start = 0 ; //variabele start is 0 $end = $ndays; //variabele end is gelijk aan variabele ndays } else { //anders, dus als ndays wel gelijk is aan 7 if($day == 0){ //als variabele day gelijk is aan 0 $dayofweek = 6; //variabele day of week = 6 } else {//anders dus als variabele day niet gelijk is aan 0 $dayofweek = $day - 1; //variabele dayofweek = gelijk aan variabele day - 1 } $start = 0 - $dayofweek; //variabele start = 0 - dayofweek $end = 7 - $dayofweek; //variabele end = 7 - dayofweek } for($i = $start; $i < $end; $i++)//variabele i = gelijk aan variabele start en zolang i lager is als variabele end onderstaande code uitvoeren en 1 optellen bij variabele i { $mktimestring = mktime(0,0,0, self::$cmonth, self::$cday, self::$cyear) + (86400 * $i);//variabele mktimestring maakt een tijd van de stringwaardes uit cmonth, cday en cyear $selection[] = $mktimestring;//variabele selection = gemaakte tijd in variabele mktimestring } self::calendarDisplayWeek($selection);//functie calendardisplayweek aanroepen met als ingevulde waarde de variabele $selection } }//einde functie calendarvday function calendarDisplayWeek($selection){//functie openen en als ingevoerde waarde de variabele selection gebruiken $html = new template(self::$wtemplate);//htmlcode importeren $html->set("begindate", date("F d, Y", $selection[0]));//datums zetten voor weergaven juiste week $html->set("enddate", date("F d, Y", $selection[count($selection)-1])); for($x = 0; $x < count($selection); $x++) {//aantal kolommen ophalen en plaatsen $html->set("width", floor(700 / count($selection)));//breedte van de tabel instellen en aantal rijen $html->set("dayname", date("d - l", $selection[0] + (86400 * $x+1)));//kolom dayname invoegen $html->parse("daynames");//gegevens parsen } for($i = 0; $i <= 23; $i++)//voor elk uur een rij toevoegen $i is de tijd { //in de loop een query uitvoeren die alle reserveringen ophaalt op dat tijdstip. Het uur($i) moet dus tussen de opgegeven vandatum en totdatum liggen. Van $i moeten we dus een datetyme functie maken en vervolgens de query uitvoeren. Hier maken we 2 functies van namelijk om van $i een datetyme te maken en een functie waarin de query's staan. Zolang deze query resultaat oplevert moet dit resultaat worden getoond in de cel en het aantal resultaten moet worden geteld.(dmv een loop) Door het aantal te tellen kunnen we de cellbreedte delen door het aantal resultaten. $html->clear("days"); if ($i >= 8 && $i <= 17){ $style = "weekrow1";//sijl van de rijen weergeven } else { $style = "weekrow0"; } for($x = 0; $x < count($selection); $x++) { $html->parse("days"); } $html->set("hour", sprintf("%02d", $i)); $html->set("style", $style); $html->parse("hours"); } $html->parse(); $html->spit(); $calendartype = 1; self::calendarShowReservations(); } function setMonthTemplate($template) { if(file_exists($template)) { self::$mtemplate = $template; } } Now i have a little problem, i have to adjust the code on that way, that is shows some reservations form the database. All this reservation are placed in a array. To show this reservation, some cells in this table has to be merged, how do i do this? PLEASE HELP! Link to comment https://forums.phpfreaks.com/topic/145531-merge-cells-in-a-template-class-real-challenge/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.