Her et et link til et billede så I kan få idéen:
http://pokerresulta.ter.dk/kkal.jpg
og nederst er hele koden til at fremtrylle denne lækre tabel :D
Hilsen
Jesper
-----------------------------
<?php
include("connectmysqli.php");
header("Content-Type: text/javascript");
$Ugetal = $_GET["ugenummer"];
$Aftalelng = $_GET["aftalemin"];
$Abnetid = $_GET["dagstarter"];
$Lukketid = $_GET["dagslutter"];
$Behandler = $_GET["behandler"];
$Visdage = "x";
$Visdage .= $_GET["visdage"];//1-7 f.eks 12345 for man-fre eller
1357 for hveranden dag
$Font = $_GET["fontface"];
$Fontsize = $_GET["fontsize"];
// LOKAL TEST
/*
$Ugetal = 0; //virker
$Aftalelng = 60; //virker
$Abnetid = "09:00:00"; //virker
$Lukketid = "18:00:00"; //virker
$Behandler = 15; //virker
$Visdage = "x1234567";//1-7 f.eks 12345 for man-fre eller 1357
for hveranden dag
$Font = "";
$Fontsize = 10;
*/
//Find ud af dagen i dag
$week2 = array( );
$nu = strtotime("now"); //== 6
$nutal = strftime("%w", $nu);
if($nutal == 0)
$nutal = 7;
//Find ud af hvilken uge der skal vises
if($Ugetal==0)
$tmpNutal = $nutal;
else
$tmpNutal = $nutal-($Ugetal*7);
$tmpNutal2 = $tmpNutal;
$span = strlen($Visdage)-1; //to get rid of the x
$startdato;
$slutdato;
$arstal;
$MinutesAllDay;
//Start tabel
//------------ HEADER --------------------
print "document.write('<table border=0
cellspacing=0><tr><td></td><td colspan=$span>');";
if ($Ugetal < 0){
print "document.write('Uge: ');"; $ugenr =
strftime("%W",strtotime(sprintf("-%u day",abs($tmpNutal2-1))));
print "document.write('$ugenr');";
}
else{
print "document.write('Uge: ');"; $ugenr =
strftime("%W",strtotime(sprintf("+%u day",abs($tmpNutal2-1))));
print "document.write('$ugenr');";
}
$arstal = strftime("%Y",strtotime(sprintf("+%u
day",abs($tmpNutal2-1))));
if ($tmpNutal2-1<0)
$startdato = strftime("%d/%m",strtotime(sprintf("+%u
day",abs($tmpNutal2-1))));//convertere minusdage til plusdage (it
really really works :)
else
$startdato = strftime("%d/%m",strtotime(sprintf("-%u
day",$tmpNutal2-1)));
$tmpNutal2 = $tmpNutal2-7;
if ($tmpNutal2-1<0)
$slutdato = strftime("%d/%m",strtotime(sprintf("+%u
day",abs($tmpNutal2))));//convertere minusdage til plusdage (it
really really works :)
else
$slutdato = strftime("%d/%m",strtotime(sprintf("-%u
day",$tmpNutal2)));
print "document.write(', ');"; print
"document.write('$startdato');"; print "document.write(' - ');";
print "document.write('$slutdato');"; print "document.write('
$arstal');";
print "document.write('</td></tr>');";
//------------- HEADER SLUT -----------------------
//------------- DAGSRÆKKE -------------------------
//Start tabel
print "document.write('<tr><td></td>');";
$week2[] = strtotime(sprintf("-200 day"));//convertere minusdage
til plusdage (it really really works :)
//Fyld uge-array med de rigtige dato'er
for ($count = 0; $count < 7; $count++){ //alle 7 dage
$count2=$count+1;
if(strpos($Visdage, strval($count+1))){
if ($tmpNutal-1<0){
$week2[] = strtotime(sprintf("+%u
day",abs($tmpNutal-1)));//convertere minusdage til plusdage (it
really really works :)
print "document.write('<td width=30>');";
switch (strftime("%w",strtotime(sprintf("+%u
day",abs($tmpNutal-1))))){
case 0: print "document.write('Søn');"; break;
case 1: print "document.write('Man');"; break;
case 2: print "document.write('Tirs');"; break;
case 3: print "document.write('Ons');"; break;
case 4: print "document.write('Tors');"; break;
case 5: print "document.write('Fre');"; break;
case 6: print "document.write('Lør');"; break;
}
print "document.write('</td>');";
}
else{
$week2[] = strtotime(sprintf("-%u day",$tmpNutal-1));
print "document.write('<td width=30>');";
switch (strftime("%w",strtotime(sprintf("-%u
day",$tmpNutal-1)))){
case 0: print "document.write('Søn');"; break;
case 1: print "document.write('Man');"; break;
case 2: print "document.write('Tirs');"; break;
case 3: print "document.write('Ons');"; break;
case 4: print "document.write('Tors');"; break;
case 5: print "document.write('Fre');"; break;
case 6: print "document.write('Lør');"; break;
}
print "document.write('</td>');";
}
}
$tmpNutal--;
}
print "document.write('</tr>');";
//--------------- DAGSRÆKKE SLUT ----------------------
$dagstart = strftime("%Y/%m/%d #replace", $week2[1]);
$dagstart = str_replace("#replace", $Abnetid, $dagstart);
$aftalestartenc = strtotime($dagstart);
$dagslut = strftime("%Y/%m/%d #replace", $week2[1]);
$dagslut = str_replace("#replace", $Lukketid, $dagslut);
$dagslutenc = strtotime($dagslut);
$SecondsAllDay = $dagslutenc-$aftalestartenc;
$MinutesAllDay = ($SecondsAllDay/60); //now its in minutes
$NmbOfRows = (($MinutesAllDay)/$Aftalelng);
$TDHeight = $NmbOfRows*40;
$LocalAftaleStart;
$aftaleslut;
$isFirstRun = true;
foreach($week2 as $getdag){
if($isFirstRun){ //lav kollonne med tider
print"document.write('<tr><td height=$TDHeight>');";
while($aftalestartenc < $dagslutenc){
$aftalestartenc2 = $aftalestartenc;
$aftalestart1 = strftime("%Y/%m/%d %H:%M:%S",
$aftalestartenc2);
$tmp= substr($aftalestart1,11,5);
print "document.write('<div
style=\"height:40;\">$tmp</div>');";
$aftalestartenc = strtotime($aftalestart1);
$aftalestartenc = $aftalestartenc+($Aftalelng*60);
}
$isFirstRun = false;
print"document.write('</td>');";
}
else{ //lav farverne
//Hent aftaler og check om den skal være rød eller grøn
$aftalestarttmp = strftime("%Y/%m/%d #replace", $getdag);
$aftalestart = str_replace("#replace", $Abnetid,
$aftalestarttmp);
$aftalesluttmp = strftime("%Y/%m/%d #replace", $getdag);
$aftaleslut = str_replace("#replace", $Lukketid,
$aftalesluttmp);
$LocalAftaleStart = $aftalestart;
//if(strtotime($aftalestart) < strttotime($aftaleslut)){
$tmp;
print "document.write('<td height=$TDHeight>');";
$query = "SELECT starttime, endtime, itemcolorhtml FROM
AFTALER WHERE ((starttime >= '$aftalestart' and starttime <
'$aftaleslut') OR (starttime < '$aftalestart' and endtime >
'$aftalestart')) and behandler = $Behandler order by starttime,
endtime";
$result = mysqli_query($link,$query) or die("Forespørgslen
(tidsoversigt) lykkedes ikke : " . mysqli_error($link));
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if(strtotime($row[starttime])< strtotime($aftalestart)){
$tmp = strtotime($row[endtime]) -
strtotime($LocalAftaleStart); //seconds from abningstid to first
appointment end
$divpercent = round((($tmp/60)*100)/$MinutesAllDay,2);
print "document.write('<div style=\"height:$divpercent%;
font-size:0px; background-color:$row[itemcolorhtml]; border: 0px;
margin: 0px; padding:0;\"></div>');";
$LocalAftaleStart = $row[endtime];
}
else{
$tmp = strtotime($row[starttime]) -
strtotime($LocalAftaleStart); //seconds from abningstid to first
appointment
$divpercent = round((($tmp/60)*100)/$MinutesAllDay,2);
if($divpercent)
print "document.write('<div style=\"height:$divpercent%;
font-size:0px; background-color:green; border: 0px; margin: 0px;
padding:0px; line-height:0;\"></div>');";
if(strtotime($row[endtime]) > strtotime($aftaleslut)){
$tmp = strtotime($aftaleslut) -
strtotime($row[starttime]); //seconds from starttid to lukketid
$LocalAftaleStart = $aftaleslut;
}
else{
$tmp = strtotime($row[endtime]) -
strtotime($row[starttime]); //seconds from starttid to sluttid
$LocalAftaleStart = $row[endtime];
}
$divpercent = round((($tmp/60)*100)/$MinutesAllDay,2);
print "document.write('<div style=\"height:$divpercent%;
font-size:0px; background-color:$row[itemcolorhtml]; border: 0px;
margin: 0px; padding:0;\"></div>');";
}
}
// Befri resultatet fra hukommelseN
mysqli_free_result($result);
if(strtotime($LocalAftaleStart) < strtotime($aftaleslut)){
$tmpo = strtotime($aftaleslut) -
strtotime($LocalAftaleStart); //seconds from last appointment to
lukketid
$divpercento = round((($tmpo/60)*100)/$MinutesAllDay,2);
print "document.write('<div style=\"height:$divpercento%;
font-size:0px; background-color:green; border: 0px; margin: 0px;
padding:0;\"></div>');";
}
print "document.write('</td>');";
}
}
print "document.write('</tr>');";
print "document.write('</table>');";
// Luk forbindelsen
mysqli_close($link);
?>
--
Vil du lære at kode HTML, XHTML, CSS, SSI, ASP eller ASP.NET?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! =>
http://www.html.dk/tutorials