Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1) For this assignment part 1, you will create a form and a PHP processor f

ID: 3798632 • Letter: P

Question

Part 1)

For this assignment part 1, you will create a form and a PHP processor for it. The form will allow the user to select some styling options such as text color, font family, etc. (Include at least 3 style attributes.) The form will also contain a text area where the user can type a paragraph or more of text. The form processor will use the styling selections to style the text typed in the text area and produce a page displaying the content of the text area. For simplicity, use an embedded style sheet to achieve this effect. The contents of this style sheet will be produced by PHP from the submitted form data. Use a method that avoids relying on the form values being valid style attributes. In other words, for the form elements use your own choices for names, and then convert these to style attributes in the PHP. For example, instead of having a form menu option whose value is Times Roman and inserting that value directly into the style sheet, give that option a name like times and have the PHP convert it to "Times Roman" for the style sheet. You can have a static HTML form and a separate PHP processor script, or an all-in-one script that both generates the form and processes it.

Part 2)

Description Your PHP code should display a calendar page. The top of the calendar states the day and time being displayed. The calendar is a table where the first column lists hours starting from the current hour to a final hour (where the final hour is the current hour + some number between 0 and 12). For example, if the time is now is 3.32 pm, the first hour should read 3.00 pm and the last hour is determined by a variable called hours_to_show. If hours_to_show is set at 12, then the last hour shown in the column should be 3.00 pm. The subsequent columns correspond to people. You should display a minimum of 3 or as many you prefer.

Directions

Please note the requirements are as follows the number of hours being displayed is set by a variable. Therefore this variable will be set to 12 at the start, however, this means that the number of rows in the table cannot be assumed to be known and you cannot simply write XHTML meaning not STATIC for 12 rows.

I have prepared a CSS file for you that you can use to style your calendar. You can get the CSS here. This is just for your convenience. You may choose to write your own CSS if you so desire. When using my CSS file please note that certain elements need to be given appropriate ids or classes. Please be aware to see what elements need to be given class or id labels.

General notes

Make sure that your file has correct permissions set. php files should have permissions set to 755 or if you prefer: -rwxr-xr-x. Which means that it should be: read for owner group and other and write for owner and execute for owner group and other.

For debugging purposes you can change the top line to be: #!/usr/local/bin/php -d display_errors=STDOUT and you will get error output on your document, which makes finding syntax errors much easier.

Requirements

Your program should be called calendar.php and should reside in your public directory along with a CSS file called callendar.css that styles it.

When your program is finished, create a text file called calendar.txt and copy and paste the contents of your calendar.php file into calendar.txt. Put calendar.txt in your public directory as well.

Your calendar must be generated by PHP script.

By default when your page is loaded it should display current day, date and time.

Your program must use a function called get_hour_string to get the hours for the first column of the calendar table. This function takes a single argument of a timestamp and returns a string indicating an hour. For example, the value returned might be: "8.00am".

The table is rendered by PHP the number of rows displayed is determined by a variable hours_to_show, which you may set equal to 12.

The rows should alternate in background color. Make sure the following files are uploaded to your public_html directory.

calendar.php calendar.txt calendar.css

Explanation / Answer

part1.php

<!DOCTYPE html>
<html>
<head>
<title>Project 2</title>

<style>
.text {

}

textarea {
   width: 600px;
   height: 120px;
   border: 3px solid #cccccc;
   padding: 5px;
  
   <?php
  
   if(isset($_POST['submit'])){
       echo "font-family: ";
       switch ($_POST["font"]) {
       case "times":
           echo "Times New Roman";
           break;
       case "sans":
           echo "sans-serif";
           break;
       case "arial":
           echo "arial";
           break;
       case "courier":
           echo "courier";
           break;
       }
       echo ";";
       echo "color: " . $_POST["font-color"] . ";";
       echo "background-color: " . $_POST["background-color"] . ";";
       echo "font-size: " . ($_POST["font-size"] * 2) . "px;";
      
   }
   ?>;
  
}

</style>

</head>

<body>

<div class = "text">
   <textarea rows="4" cols="50">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea>
</div>

<h1>Style Options</h1>

<form method = "POST">
   <h2>Font</h2>
   <select name="font">
       <option value="times">Times New Roman</option>
       <option value="sans">Sans-Serif</option>
       <option value="arial">Arial</option>
       <option value="courier">Courier New</option>
   </select>
  
   <h2>Font Size (Between 8 and 20)<h3>
   <!--<input type="number" name="quantity" min="8" max="24">-->
   8<input type="range" name="font-size" min="4" max="12">24
  
   <h2>Font Color</h2>
   <select name="font-color">
       <option value="black">black</option>
       <option value="red">red</option>
       <option value="blue">blue</option>
       <option value="green">green</option>
       <option value="orange">orange</option>
   </select>
  
   <h2>Background Color</h3>
   <select name="background-color">
       <option value="white">white</option>
       <option value="Beige">beige</option>
       <option value="Gainsboro">light gray</option>
       <option value="GreenYellow">green-yellow</option>
       <option value="MistyRose">light pink</option>
   </select>
   <br><br>
   <input type="submit" value="submit" name = "submit">

</form>

</body>
</html>


calendar.css

*
{
   margin:0;
   padding:0;
}

body
{
   background-color:#7BA3BE;
   font-family:verdana;
   font-size:12px;
}

h1
{
   font:18pt verdana;
   margin-left:10px;
}

#event_table
{
   border-collapse:collapse;
   border-top:5px;
   margin:5px 10px 10px;
}

#event_table .table_header
{
   color:#000;
   font-size:24px;
   font-weight:400;
   padding-left:5px;
   text-align:left;
   text-decoration:none;
   width:220px;
}

#event_table .even_row
{
   background-color:#86cefd;
   height:40px;
}

#event_table .odd_row
{
   background-color:#BCE4FE;
   height:40px;
}

#event_table .hr_td
{
   text-align:right;
   width:60px;
}

.container
{
   background-color:#FFF;
   border:5px solid #000;
   font:12px Verdana, Arial, Helvetica, sans-serif;
   margin:20px auto;
   padding:0;
   width:760px;
}

#next
{
   float:right;
   margin-bottom:10px;
   margin-right:10px;
}

#prev
{
   float:left;
   margin-bottom:10px;
   margin-left:10px;
}

#today
{
   margin-bottom:10px;
   margin-left:auto;
   margin-right:auto;
   width:100px;
}

calendar.php

<!DOCTYPE html>
<html>

    <link rel="stylesheet" type="text/css" href="calendar.css" />

    <head>
        <title>Part 2</title>
    </head>

    <body>

        <?php
            date_default_timezone_set('America/New_York');

            $hours_to_show = 11;
           if(isset($_POST['submit'])){
               $hours_to_show = $_POST["hours_to_show"] - 1;
           }
            $timeStamp = time();
            $todayDate = date("D, F j, Y", $timeStamp);                                                  
            $currentTime = date("g:i a",$timeStamp);   
            $todayDay = date("l", $timeStamp);

            function get_hour_string($timeStamp){
                $hour = date("g", $timeStamp);
                $am_or_pm = date("a", $timeStamp);
                return "$hour:00 $am_or_pm";
            }

        ?>
      
        <div class="container">
            <h1>
                <?php
                    echo "<br><b>Welcome to my calendar!</b><br>";
                    echo "<br><b>The day of the week</b>: $todayDay";
                    echo "<br><b>Today's date</b>: $todayDate";
                    echo "<br><b>The current time is</b> $currentTime <br>";
                ?>
               <form method="POST">
                   Hours to show: <input type="number" name="hours_to_show">
                   <input type="submit" value="submit" name = "submit">
               </form>
            </h1>
            <table id="event_table">
            <tr>  
                <th class='hr_td'></th>
                <th class='table_header'>&nbsp&nbsp&nbsp&nbsp&nbspForrest</th>
                <th class='table_header'>&nbsp&nbsp&nbsp&nbsp&nbspLouis</th>
                <th class='table_header'>&nbsp&nbspHenry</th>
            </tr>
            <tr> <br> </tr>

        <?php

        for ($i = 0; $i <= $hours_to_show; $i++) {
            $hours = get_hour_string($timeStamp + $i * 60 * 60);
            if ($i % 2 == 0) {

                echo "<tr class='even_row'> ";
                echo "<td class='hr_td'>
                            <b>$hours</b>
                      </td>
                      <td> </td>                      
                      <td> </td>
                      <td> </td> ";
                echo "</tr> ";

            }

            if ($i % 2 != 0) {

                echo "<tr class='odd_row'> ";
                echo "<td class='hr_td'>
                            <b>$hours</b>
                      </td>
                      <td> </td>
                      <td> </td>
                      <td> </td> ";

                echo "</tr> ";
            }
        }
        ?>  
            </table>
        </div>

    </body>
</html>


calendar.txt


<!DOCTYPE html>
<html>

    <link rel="stylesheet" type="text/css" href="calendar.css" />

    <head>
        <title>Part 2</title>
    </head>

    <body>

        <?php
            date_default_timezone_set('America/New_York');

            $hours_to_show = 11;
           if(isset($_POST['submit'])){
               $hours_to_show = $_POST["hours_to_show"] - 1;
           }
            $timeStamp = time();
            $todayDate = date("D, F j, Y", $timeStamp);                                                  
            $currentTime = date("g:i a",$timeStamp);   
            $todayDay = date("l", $timeStamp);

            function get_hour_string($timeStamp){
                $hour = date("g", $timeStamp);
                $am_or_pm = date("a", $timeStamp);
                return "$hour:00 $am_or_pm";
            }

        ?>
      
        <div class="container">
            <h1>
                <?php
                    echo "<br><b>Welcome to my calendar!</b><br>";
                    echo "<br><b>The day of the week</b>: $todayDay";
                    echo "<br><b>Today's date</b>: $todayDate";
                    echo "<br><b>The current time is</b> $currentTime <br>";
                ?>
               <form method="POST">
                   Hours to show: <input type="number" name="hours_to_show">
                   <input type="submit" value="submit" name = "submit">
               </form>
            </h1>
            <table id="event_table">
            <tr>  
                <th class='hr_td'></th>
                <th class='table_header'>&nbsp&nbsp&nbsp&nbsp&nbspForrest</th>
                <th class='table_header'>&nbsp&nbsp&nbsp&nbsp&nbspLouis</th>
                <th class='table_header'>&nbsp&nbspHenry</th>
            </tr>
            <tr> <br> </tr>

        <?php

        for ($i = 0; $i <= $hours_to_show; $i++) {
            $hours = get_hour_string($timeStamp + $i * 60 * 60);
            if ($i % 2 == 0) {

                echo "<tr class='even_row'> ";
                echo "<td class='hr_td'>
                            <b>$hours</b>
                      </td>
                      <td> </td>                      
                      <td> </td>
                      <td> </td> ";
                echo "</tr> ";

            }

            if ($i % 2 != 0) {

                echo "<tr class='odd_row'> ";
                echo "<td class='hr_td'>
                            <b>$hours</b>
                      </td>
                      <td> </td>
                      <td> </td>
                      <td> </td> ";

                echo "</tr> ";
            }
        }
        ?>  
            </table>
        </div>

    </body>
</html>