15. november 2005 - 18:19
Der er
5 kommentarer og 1 løsning
Bevar check-box markeringer når siden skiftes
Hej Eksperter, Jeg har skrevet et kalender-booking-script, som bare mangler én lille detalje. Man kan bladre igennem årene og månederne – enten pr. en select-boks eller de to frem og tilbage knapper – og datoerne skifter, hvorefter man kan afkrydse de forskellige datoer, hvor man har lyst til at booke, hvorefter man klikker reserver for at komme hen til en formular. Problemet ligger i, at hvis man går tilbage og frem i månederne eller årene, forsvinder de gamle dato-markeringer. Indtil nu har jeg selv kæmpet lidt med det, men jeg må overgive mig.
Annonceindlæg fra SoftwareOne
15. november 2005 - 18:19
#1
Koden ser sådan ud (meget overfladisk materiale): <?php ########################################## ## ## ## (C) COPYRIGHT 2005: ## ## Kasper Lauritzen ## ## eks_fejl@hotmail.com ## ## ## ########################################## require("dbase.php"); echo "<title>Booking</title>"; if (isset($HTTP_GET_VARS['m'])){ $month = $HTTP_GET_VARS['m']; }else{ $month = date("n"); } if (isset($HTTP_GET_VARS['y'])){ $year = $HTTP_GET_VARS['y']; }else{ $year = date("Y"); } if ($month > 12){ $month = 12; }elseif($month < 1){ $month = 1; } $for_year = $year-1; $nex_year = $year+1; if ($month == 1){ $for_month = "12&y=".$for_year; $nex_month = "2&y=".$year; }elseif ($month == 12){ $nex_month = "1&y=".$nex_year; $for_month = "11&y=".$year; }else{ $for_month = $month-1 . "&y=" . $year; $nex_month = $month+1 . "&y=" . $year; } $for_year_true = "true"; $nex_year_true = "true"; $for_month_true = "true"; $nex_month_true = "true"; if ($for_year < $start_aar){ $for_year_true = "false"; } if ($nex_year > $start_aar+$max_year_frem-1){ $nex_year_true = "false"; } $for_year_til_month = $start_aar-1; $nex_year_til_month = $start_aar+$max_year_frem; if ($for_month == "12&y=".$for_year_til_month){ $for_month_true = "false"; } if ($nex_month == "1&y=".$nex_year_til_month){ $nex_month_true = "false"; } $for_year = $for_year . "&m=" . $month; $nex_year = $nex_year . "&m=" . $month; $maanederne = array(1 => "Januar", 2 => "Februar", 3 => "Marts", 4 => "April", 5 => "Maj", 6 => "Juni", 7 => "Juli", 8 => "August", 9 => "September", 10 => "Oktober", 11 => "November", 12 => "December"); $dagene = array(1 => "Mandag", 2 => "Tirsdag", 3 => "Onsdag", 4 => "Torsdag", 5 => "Fredag", 6 => "Lørdag", 7 => "Søndag"); $rakkerne = array(); $antal_days_month = date("t", mktime(0, 0, 0, $month, 1, $year)); if (date("w", mktime(0, 0, 0, $month, 1, $year)) != 0){ for($i=1; $i<date("w", mktime(0, 0, 0, $month, 1, $year)); $i=$i+1){ $rakkerne[] = '-'; } }else{ $rakkerne[] = '-'; $rakkerne[] = '-'; $rakkerne[] = '-'; $rakkerne[] = '-'; $rakkerne[] = '-'; $rakkerne[] = '-'; } for($i=1; $i<$antal_days_month+1; $i=$i+1){ $rakkerne[] = $i; } $dertil = date("w", mktime(0, 0, 0, $month, 1, $year))+date("w", mktime(0, 0, 0, $month, 1, $year)); for($i=$dertil;$i<43;$i=$i+1){ $rakkerne[] = '-'; } ?> <Script Language="JavaScript"> function year_change(tal,maaned,fil){ document.location="?y="+tal+"&m="+maaned; } function month_change(tal,aar){ document.location="?y="+aar+"&m="+tal; } </Script> <?php echo "<link rel='stylesheet' type='text/css' href='style.css'>"; echo "<form>"; echo "<table border=1>"; echo "<tr>"; echo "<td colspan=2 align=center>"; if ($for_month_true == "true"){ echo "<a href='?m=".$for_month."' class='ret'><<</a> "; } echo "<select name='mo' onchange='month_change(form.mo.value,\"".$year."\")'>"; for ($i = 1; $i < 13; $i=$i+1){ if ($i == $month){ echo "<option value='".$i."' selected>".$maanederne[$i]; }else{ echo "<option value='".$i."'>".$maanederne[$i]; } } echo "</select>"; if ($nex_month_true == "true"){ echo " <a href='?m=".$nex_month."' class='ret'>>></a>"; } /* <BOOKING-tekst> */ echo "<td colspan=3 align=center><h1 class='cal_over'>Booking:"; /* </BOOKING-tekst> */ echo "<td colspan=2 align=center>"; if ($for_year_true == "true"){ echo "<a href='?y=".$for_year."' class='ret'><<</a> "; } echo "<select name='ye' onchange='year_change(form.ye.value,\"".$month."\")'>"; for ($i = $start_aar; $i < $start_aar+$max_year_frem; $i=$i+1){ if ($i == $year){ echo "<option value='".$i."' selected>".$i; }else{ echo "<option value='".$i."'>".$i; } } echo "</select>"; if ($nex_year_true == "true"){ echo " <a href='?y=".$nex_year."' class='ret'>>></a>"; } echo "</tr>"; echo "<tr>"; for ($i = 1; $i < 8; $i=$i+1){ echo "<td width=12% align=center class='dag-over'>".$dagene[$i].":"; } echo "</tr>"; function writeit($tal,$month,$year,$iet){ require("dbase.php"); $endato = "dato"; $enkat = "katagori"; $today_day = date("j"); $today_month = date("n"); $today_year = date("Y"); if ($tal != '-'){ $datokode = "d" . $tal . "m" . $month . "y" . $year; mysql_select_db("$dbasen"); $result = mysql_query("SELECT * FROM $tabel WHERE $endato = CONVERT(_utf8 '$datokode' USING latin1) COLLATE latin1_swedish_ci") or die(mysql_error()); $row = mysql_fetch_array($result); if ($row != null){ if ($row["$enkat"]=='0'){ $lere = "reser"; }else{ $lere = "bestil"; } }else{ $lere = "ledig"; } mysql_close($conn); if ($lere == "ledig"){ if (($tal == $today_day) AND ($month == $today_month) AND ($year == $today_year)){ echo "<td class='".$lere."'><input type=checkbox value='d".$tal."m".$month."y".$year."' name='datoer[]'><span class='today'>".$tal."</span>"; }else{ echo "<td class='".$lere."'><input type=checkbox value='d".$tal."m".$month."y".$year."' name='datoer[]'><span class='dato'>".$tal."</span>"; } }else{ if (($tal == $today_day) AND ($month == $today_month) AND ($year == $today_year)){ echo "<td class='".$lere."'><input type=checkbox value='d".$tal."m".$month."y".$year."' name='datoer[]' disabled><span class='today'>".$tal."</span>"; }else{ echo "<td class='".$lere."'><input type=checkbox value='d".$tal."m".$month."y".$year."' name='datoer[]' disabled><span class='dato'>".$tal."</span>"; } } }elseif($iet == 41){ echo "<td align=right valign=bottom><img src='admin.bmp' border=0 height=20 alt='Administrator-login'>"; }else{ echo "<td align=center>-"; } } require("rydop.php"); echo "</form>"; /* SKRIV KALENDER */ echo "<form action='book.php' method='post'>"; echo "<tr>"; for ($i = 0; $i < 7; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "<tr>"; for ($i = 7; $i < 14; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "<tr>"; for ($i = 14; $i < 21; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "<tr>"; for ($i = 21; $i < 28; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "<tr>"; for ($i = 28; $i < 35; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "<tr>"; for ($i = 35; $i < 42; $i=$i+1){ writeit($rakkerne[$i],$month,$year,$i); } echo "</tr>"; echo "</table>"; echo "<input type=submit value='Reserver'>"; echo "</form>"; ?>