0

以前の日付を利用できないカレンダーを使用しています。現在、私のカレンダーには各日付のリンクがあり、日付をクリックすると別のページに値が表示されます。ただし、すでに過ぎたすべての日付を使用できないようにする必要があります。コードの末尾近くにある if ステートメントと関係があることはわかっていますが、わかりません。これが私のコードです

<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July", 
"August", "September", "October", "November", "December");
?>
<?php
$cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : date("n");
$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");

$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;

if ($prev_month == 0 ) {
    $prev_month = 12;
    $prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
    $next_month = 1;
    $next_year = $cYear + 1;
}
?><!DOCTYPE html>
<html>
<head>
<title>Hook Up</title>
</head>
<style type="text/css">
        table {
        border: 1px solid black;
        border-collapse: collapse;
    }
    th {
        border: 1px solid black;
        padding: 6px;
        font-weight: bold;
        background: #ccc;
    }
    td {
        border: 1px solid black;
        padding: 6px;
        vertical-align: top;
        width: 100px;
        }
</style>
<script type="text/javascript">
function eventWindow(url) {
        event_popupWin = window.open(url, 'event',
        'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
        event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Night Out</h1>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=".                     $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=".  $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a>  </td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo    $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
</tr>
<?php 
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
$today = date('j');
$currentmonth = date('n');
for ($i=0; $i<($maxday+$startday); $i++) {
if(($i % 7) == 0 ){
echo "<tr>";
}
if($i < $startday){
echo ("<td class='cell cell_txt'> </td>");
} else {
if (($i - $startday + 1) == $today && $currentmonth == $cMonth){
echo ("<td class='cell_today cell_txt'>".($i-$startday+ 1)."</td>");
} else {
echo ("<td class='cell cell_txt'><a href=\"hook.php?day=".($i - $startday +   1)."&amp;month=".$cMonth."&amp;year=".$cYear."\">".($i - $startday + 1)."</a></td>");
}
}
if(($i % 7) == 6 ) {
echo "</tr>\n";
}
}
?>
</table>
</td>
</tr>
</table>
</body>
    </html> 

誰かが助けることができれば、それは大歓迎です。乾杯

4

2 に答える 2

0

次の行を追加すると

$cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : date("d");

この線の下

$cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : date("Y");

この行を変更します

if (($i - $startday + 1) == $today && $currentmonth == $cMonth){

に:

if ((($i - $startday + 1) == $today && $currentmonth == $cMonth) OR ( (($i - $startday + 1) == $cDay) && ($currentmonth == $cMonth))  ){

渡された日付が黒くなります。

複数の日付を渡す場合、つまり1つの日付2013-01-18を選択する場合、ページはリロードして18日を空白にし、次に2番目の日付(2013-01-22など)を選択してページをリロードし、両方を空白にします。 18日と22日は、配列への入力を変更し、以前に選択した日付を非表示のフィールドに追加して再送信する必要があります。

1つの日付をブラックアウトしたいだけの場合は、コードの変更が機能します。

お役に立てれば。

選択した前の日付をすべてブラックアウトするように更新します。

<?php
    $monthNames = Array("January", "February", "March", "April", "May", "June", "July",
        "August", "September", "October", "November", "December");
    ?>
    <?php
    $sMonth = isset($_REQUEST["smonth"]) ? $_REQUEST["smonth"] : date("n");
    $sYear = isset($_REQUEST["syear"]) ? $_REQUEST["syear"] : date("Y");
    $cMonth = isset($_REQUEST["month"]) ? $_REQUEST["month"] : '';
    $cYear = isset($_REQUEST["year"]) ? $_REQUEST["year"] : '';
    $cDay = isset($_REQUEST["day"]) ? $_REQUEST["day"] : '';

    //echo __line__." Dates in ".$cDay." ".$cMonth.", ".$cYear."<br>";

    $prev_year = $sYear;
    $next_year = $sYear;
    $prev_month = $sMonth - 1;
    $next_month = $sMonth + 1;

    if ($prev_month == 0) {
        $prev_month = 12;
        $prev_year = $sYear - 1;
    }
    if ($next_month == 13) {
        $next_month = 1;
        $next_year = $sYear + 1;
    }
    $nextPrevString = "&amp;month=$cMonth&amp;year=$cYear&amp;day=$cDay";
    $selectString = "&amp;smonth=$sMonth&amp;syear=$sYear";
    ?><!DOCTYPE html>
    <html>
        <head>
            <title>Hook Up</title>
        </head>
        <style type="text/css">
            table {
                border: 1px solid black;
                border-collapse: collapse;
            }
            th {
                border: 1px solid black;
                padding: 6px;
                font-weight: bold;
                background: #ccc;
            }
            td {
                border: 1px solid black;
                padding: 6px;
                vertical-align: top;
                width: 100px;
            }
        </style>
        <script type="text/javascript">
            function eventWindow(url) {
                event_popupWin = window.open(url, 'event', resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400);
                event_popupWin.opener = self;
            }
        </script>
        <body>
            <h1>Select a Night Out</h1>
            <table width="200">
                <tr align="center">
                    <td bgcolor="#999999" style="color:#FFFFFF">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td width="50%" align="left">  <a href="<?php echo $_SERVER["PHP_SELF"] . "?smonth=" . $prev_month . "&syear=" . $prev_year . $nextPrevString; ?>" style="color:#FFFFFF">Previous</a></td>
                                <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?smonth=" . $next_month . "&syear=" . $next_year . $nextPrevString; ?>" style="color:#FFFFFF">Next</a>  </td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="center">
                        <table width="100%" border="0" cellpadding="2" cellspacing="2">
                            <tr align="center">
                                <td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><strong><?php echo $monthNames[$sMonth - 1] . ' ' . $sYear; ?></strong></td>
                            </tr>
                            <tr>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>M</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>W</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>T</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>F</strong></td>
                                <td align="center" bgcolor="#999999" style="color:#FFFFFF"><strong>S</strong></td>
                            </tr>
                            <?php
                            $timestamp = mktime(0, 0, 0, $sMonth, 1, $sYear);
                            if ($cDay != '') {
                                $selectedDate = mktime(0, 0, 0, $cMonth, $cDay, $cYear);
                            } else {
                                $selectedDate = 0;
                            }
                            $maxday = date("t", $timestamp);
                            $thismonth = getdate($timestamp);
                            $startday = $thismonth['wday'];
                            $today = date('j');
                            $currentmonth = date('n');

                            for ($i = 0; $i < ($maxday + $startday); $i++) {
                                if (($i % 7) == 0) {
                                    echo "<tr>";
                                }
                                if ($i < $startday) {
                                    echo ("<td class='cell cell_txt'> </td>");
                                } else {
                                    $testDate = mktime(0, 0, 0, $sMonth, $i - $startday + 1, $sYear);
                                    if ($testDate < $selectedDate) {
                                        echo ("<td class='cell_today cell_txt'>" . ($i - $startday + 1) . "</td>");
                                    } else {
                                        echo ("<td class='cell cell_txt'><a href=\"" . $_SERVER['PHP_SELF'] . "?day=" . ($i - $startday + 1) . "&amp;month=" . $sMonth . "&amp;year=" . $sYear . $selectString . "\">" . ($i - $startday + 1) . "</a></td>");
                                    }
                                }
                                if (($i % 7) == 6) {
                                    echo "</tr>\n";
                                }
                            }
                            ?>
                        </table>
                    </td>
                </tr>
            </table>
        </body>
    </html> 
于 2013-01-27T11:36:34.553 に答える
0

<!-----use it will surely work -----!>

<?php
                        $monthNames = Array("January", "February", "March", "April", "May", "June", "July",
                            "August", "September", "October", "November", "December");
                        ?>

                        <?php
                        if (!isset($_REQUEST["day"])) $_REQUEST["day"] = date("d");
                        if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
                        if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
                        ?>

                        <?php
                        $cDay = $_REQUEST["day"];
                        $cMonth = $_REQUEST["month"];
                        $cYear = $_REQUEST["year"];

                        $prev_year = $cYear;
                        $next_year = $cYear;
                        $prev_month = $cMonth - 1;
                        $next_month = $cMonth + 1;

                        if ($prev_month == 0) {
                            $prev_month = 12;
                            $prev_year = $cYear - 1;
                        }
                        if ($next_month == 13) {
                            $next_month = 1;
                            $next_year = $cYear + 1;
                        }
                        ?>
                        <div id="calendar_div" name="calendar_div">
                            <div class="table-responsive">
                                <table width="93%" style="border: none">
                                    <tr>
                                        <td>&nbsp;&nbsp;<a
                                                href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $prev_month . "&year=" . $prev_year; ?>"
                                                style="color:#FFFFFF"> < </a>
                                            <a href="<?php echo $_SERVER["PHP_SELF"] . "?month=" . $next_month . "&year=" . $next_year; ?>"
                                               style="color:#FFFFFF"> > </a></td>
                                        <td style="float: right">
                                            <h3 style="color: #ffffff;">  <?php echo $monthNames[$cMonth - 1] . ' ' . $cYear; ?></strong></h3>
                                        </td>
                                    </tr>
                                </table>

                                <table  class="table">

                                    <tr>
                                        <td style="color:#FFFFFF;border: none"><strong>Sun</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Mon</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Tue</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Wed</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Thr</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Fri</strong></td>
                                        <td style="color:#FFFFFF;border: none"><strong>Sat</strong></td>
                                    </tr>

                                    <?php

                                    $timestamp = mktime(0, 0, 0, $cMonth, 1, $cYear);
                                    $maxday = date("t", $timestamp);
                                    $thismonth = getdate($timestamp);
                                    $currentmonth = date('n');

                                    $startday = $thismonth['wday'];

                                    for ($i = 0; $i < ($maxday + $startday); $i++) {
                                        if (($i % 7) == 0) echo "<tr>\n";
                                        if ($i < $startday) echo "<td style='border: none'></td>\n";
                                        elseif(($i - $startday + 1) == $cDay && $currentmonth == $cMonth ){



                                            echo "<td  style='background-color: #cccccc'>". ($i - $startday + 1) ."</td>";}

                                        else{

                                            echo "<td  style='color: #ffffff; border: none'>". ($i - $startday + 1) ."</td></a>";}

                                        if(($i % 7) == 6 ) echo "</tr>";

                                    }

                                    ?>


                                </table>

于 2015-02-26T11:36:19.050 に答える