Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The flow of the program is as follows: A page is displayed prompting the user for the year and the month of which to display

The flow of the program is as follows:

  1. A page is displayed prompting the user for the year and the month of which to display the calendar.
  2. The user must select the Month and the Year from the form.
  3. The user also has the option of selecting to mark a "special day" on the calendar.

If the user selects the special event they must input a special day, description and color for the event.

  1. The user then presses the "Generate Calendar" button.
  2. The form data is validated and the calendar is displayed according to the various options the user selected.

Requirements:

The program must by default seleft the current month and year.

The user can select the month and the year from two drop down lists.

Days that are not part of the calendar are greyed out.

The numbering must accuratly reflect the Calendar

All data must be validated

If the user seelcts the Mark a special Event option, the data associated with that feature must be validated as well.

Validation errors must appear on the screen. Prompting the user to fix them.

You must implement the following files & functions:

html.inc.php:

  1. html_CalendarForm() - Generates the html form to prompt the user
  2. html_Errors($errors) - Displays the User Errors.
  3. html_Calendar($data) - Displays the html Calendar based on the data from getCalendarData() validation.inc.php:

1. validate_CalendarForm() - Validates the user input and returns an array of errors.

calendar.inc.php:

1. getCalendarData($month, $year) - Generates a single array of data containing all the information for the calendar.

Hints:

A calendar is always a grid of 7x6 rows.

It might be helpful to use two loops to generate the rows for the calendar.

If you pass the months and the year as integers you can use mktime to generate the appropriate timestamp.

It may be helpful to start as a single file and move your functions to the include files when they work It may also be helpful to try and just create the grid before you tackle the data structure.

Appendix

Screenshot of the Form for the user.

image text in transcribed

image text in transcribed

require_once('inc/calendar.inc.php'); require_once('inc/validation.inc.php'); require_once('inc/html.inc.php');

//Check to see if there was information posted via the server if ($_SERVER["REQUEST_METHOD"] == "POST") {

//Looks like someone posted data //Validate it $errors = validate_CalendarForm(); //If there are no errors... if (empty($errors)) { //Get the calendar data and print it

} else { //Otherwise print the errors html_errors($errors); //And present the form. html_CalendarForm(); } } else { //Or if there was no POST data it means the user hasnt submitted anything, just pint the calendar form. html_CalendarForm(); }

?>

html_CalendarForm():

function getCalendarData($month = 05,$year = 2018 ) {

//Create a timestamp based on the parameters for getCalendarData

$calendarData = array(); //We have to set the counter to 1 and not zero because calendar days start at 1. $counter = 1;

//Important Days //First Day of the Month //Last Day of the Month

//Iterate through the grid (7 x 5) //For each row //For each column

//Append the current month and year to the array $calendarData["month"] = date('F',$ts); $calendarData["year"] = date('Y',$ts); //var_dump($calendarData); return $calendarData; }

?>

html.inc.php:

//This funciton will print out a calendar form allowing the user to select the month from a drop down and a year from the drop down menu. function html_CalendarForm() { ?>

Lab 03 - HTML Calendar - JSm_56789


Month:
Year:

Special Event Day
Description
Please selct a color.

//This function shows errors in an a div using an unorderd list function html_errors($errors) { ?>

    $error"; } ?>

//This funciton will take the data array and display the calendar function html_Calendar($data) { //Array containing the days of the week. $daysOfTheWeek = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); //Counter $counter = 0; //var_dump($data);

//Begin calendar by printing the headerO echo '

'; //Print the month and year of the Calendar (Title in the top) echo ''; echo ''; //Go through all the days of the week. echo '';

//Iterate through the array and print out the boxes for ($x = 0; $x '; for ($y = 0; $y '; } //This is to check if the counter is the same as the special day //Or just print the number (day number) in the box

} //Increment the counter $counter++; } echo ''; }

echo '

'.$data["year"].' - '.$data["month"].' - Lab03SWh_56789

'; } ?>

validation.inc.php::

//Read in post to validate form data function validate_calendar() { //Store the errors $errors = array();

//Valid months to check against. //Check the month was selected if () { $errors[] = "Please enter a valid month."; } //Check the year was selected if ( ) { $errors[] = "Please enter a valid year."; }

//Check if the checkbox was selected if () { //Check the Day is within the month if () { $errors[] = "Please enter a valid day for the month you have selected"; } if () { $errors[] = "Please enter a day for your special event."; } //Check the Description was entered if () { $errors[] = "Please enter a description"; } //Check a color was selected if () { $errors[] = "Please select a color"; } }

return $errors; }

?>

Lab 03 - HTML Calendar - JSm_56789 Month: January Year: 2019 Mark a special event. Special Event Day 1 Description New Years Day! Please selct a color. green Submit Query 2019 - January - Lab03sWh_56789 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 1-New Years Day! 25 26 2- Lab 03 - HTML Calendar - JSm_56789 Month: January Year: 2019 Mark a special event. Special Event Day 1 Description New Years Day! Please selct a color. green Submit Query 2019 - January - Lab03sWh_56789 Sunday Monday Tuesday Wednesday Thursday Friday Saturday 1-New Years Day! 25 26 2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions