Booking on Calendar

Discussion in 'PHP' started by zed420, Aug 9, 2009.

  1. #1
    Hi All
    Can someone please help me with this code all I'm trying to do is book driving lessons online via Calendar. So if someone hits on passed date,month or year he/she gets message 'The date has passed' else they can book their lesson on clicked day. There are NO errors on script but it not working right.
    thanks
    Zed
    <?php
    $day = $_GET['day'];
    $cMonth = $_GET['cMonth'];
    $cYear = $_GET['cYear'];
    $today = date("j");
    $month = date("n");
    $year = date("y");
    
    if (($day < $today)&&($cMonth <= $month)){
    	echo "<p>This date has Passed, Please choose another</p>";
    }elseif (($cMonth < $month)&&($cYear <= $year)){
    	echo "<p>This date has Passed, Please choose another</p>";
    }elseif (($cMonth >= $month)&&($cYear >= $year)){
    	echo "You are about to book a lesson for <div class=\"everyday\">$day $cMonth $cYear</div>";
    }else{
    	echo "You are about to book a lesson for <div class=\"everyday\">$day $cMonth $cYear</div>";	
    	  }
    ?>
    
    Code (markup):

     
    zed420, Aug 9, 2009 IP
  2. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #2
    Can we see the forum where it is being submitted from?
     
    Pudge1, Aug 9, 2009 IP
  3. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #3
    Thanks for your reply heres the calendar
    <html>
    <head>
    <link href="calendar.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
    
    $monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
       if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
       if (!isset($_REQUEST["year"]))  $_REQUEST["year"]  = date("Y");
       
      $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">
        <table width="400">
            <tr align="center">
              <td bgcolor="#999999" style="color:#FFFFFF">
                   <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                          <td width="50%" align="left">&nbsp;&nbsp;<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>&nbsp;&nbsp;</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");
    				   $month = date("n");
                      for ($i=0; $i<($maxday+$startday); $i++) {
    				  $day = ($i - $startday + 1);
    if(($day == $today)&&($cMonth == $month)){
    	$day = "<div class=\"today\">".($i - $startday + 1)."</div>";
    	} else { 
    	$day = ($i - $startday + 1);
    	} 
    	if(($i % 7) == 0 ) 
    	echo "<tr bgcolor=EEEEEE\n>";
        if($i < $startday)
    	echo "<td></td>\n";
       else 
    echo "<td align='center' valign='middle' height='20px'>
          <a href='test.php?day=$day&cMonth=$cMonth&cYear=$cYear' STYLE='TEXT-DECORATION: NONE'>". $day . "</a></td>\n";
    		 if(($i % 7) == 6 )
    					echo "</tr>\n";
                      } 
                  
                     ?>
                  </table>
                </td>
            </tr>
        </table>
    </div>
    </body></html>
    Code (markup):
     
    zed420, Aug 9, 2009 IP
  4. CodeSpire

    CodeSpire Guest

    Messages:
    55
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Use a UNIX timestamp.

    Convert the date strings to time ( strtotime ( ); ) - If the timestamp is in the past, throw an error.
     
    CodeSpire, Aug 9, 2009 IP
  5. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #5
    I'm not really sure what you mean? could you expand on little bit please.
    Thanks Zed:confused:
     
    zed420, Aug 10, 2009 IP
  6. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #6
    Pudge1, Aug 10, 2009 IP
  7. zed420

    zed420 Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #7
    Thanks Zed
     
    zed420, Aug 11, 2009 IP