Scheduling some code to display at the weekend

Hi all,
I have a page on the website which has an include command (which points to an html form). I want one html form to display during the week, and then at 5pm on a friday afternoon I want to display the same page but have the include command point to another html form. Then on Monday morning at 9am go back to displying the other form. For example:

<?
// display this include during the week
include ‘includes/weekday-form.php’

// display this include during the weekend
include ‘includes/weekend-form.php’
?>

How can I do this in php?
Many thanks

Hi bolton,

Try this framework which tests for three week day parameters.

  1. The first condition is a switch which allows hard-coding $day and $hour instead of actual date(…)
  2. if any test is true then include the ‘weekday-form.php’
  3. I have left test $t2 and $t3 for you to do :slight_smile:

<?php 
  // either 1 or 0 for test and actual day and time
  if(0)
  {
    $day  = date("D"); // actual day
    $hour = date("H"); // actual hour
  }else{
    $day  = "Wed";
    $hour = "16";
  }
  echo $day ,' : ', $hour;

  // three week day tests, at least one must be true
  $t1 = $t2 = $t3 = false;

  // $t1 = test for Tue, Wed or Thu
  $t1 = in_array($day, array('Tue', 'Wed', 'Thu') );
  if($t1)
  {
    echo '<br >Must be ' .$day;
  }

  // $t2 = test for Monday after 09:00

  // $t3 = test for Friday before 17:00

  $inc = 'includes/weekend-form.php' ; // set default to weekend
  if ($t1 || $t2 || $t3)
  {
    echo '<br /><br />Must be during the week';
    $inc = 'includes/weekday-form.php';
  }
  // include $inc;
?>

Thanks John - thats a big help.

Ive almost got it working. Its now working correctly apart from I can get it to detect ‘Monday before 9am’. (It detects if its the weekend or if its after 5pm on friday fine). Heres the code:

        <?php 
  // either 1 or 0 for test and actual day and time
  if(0)
  {
    $day  = date("D"); // actual day
    $hour = date("H"); // actual hour
  }else{
    $day  = "Mon";
    $hour = "01";
  }
  echo $day ,' : ', $hour;

  // three week day tests, at least one must be true
  $t1 = $t2 = $t3 = false;

  // $t1 = test for Tue, Wed or Thu
  $t1 = in_array($day, array('Tue', 'Wed', 'Thu') );
  if($t1)
  {
    echo '<br >Must be ' .$day;
  }

  // $t2 = test for Monday after 09:00
  if($day == "Mon" && $hour > 09){
	  $t2 = true;
		echo "<p>After 9am Mon! Display weekday form</p>";
	}

  // $t3 = test for Friday before 17:00
	if($day == "Fri" && $hour < 17){
		 $t3 = true;
		echo "<p>Before 5pm Fri! Display weekday form</p>";
	}

  $inc = 'includes/weekend-form.php' ; // set default to weekend
  if ($t1 || $t2 || $t3)
  {
    echo 'Must be during the week';
    $inc = 'includes/weekday-form.php';
  }else{
	  echo '<br />Must be the weekend!<br /><br />';
	 }
  // include $inc;
?>
   

What am I doing wrong with $t2 ?
Many thanks

Hi Bolton,
Try passing 09 to var_dump() and see if the variable is a string, integer, etc
Try again without the zero and try again in quotes.

Sent from a Nexus tablet.

That great - all working now.

I basically changed:

// $t2 = test for Monday after 09:00
  if($day == "Mon" && $hour > 09){
      $t2 = true;
        echo "<p>After 9am Mon! Display weekday form</p>";
    }

to

  // $t2 = test for Monday after 09:00
  if($day == "Mon" && $hour >= 9){
	  $t2 = true;
		echo "<p>After 9am Mon! Display weekday form</p>";
	}

Thanks John ! :slight_smile:

[COLOR=#333333]Hi Bolton,

Many thanks for the update and I am pleased you managed to solve your problem.

Also good that you had further problems that you managed to solve yourself rather than just cutting & pasting a solution.

Looking forward to your next hurdle :slight_smile:

Cheers,

John[/COLOR]