Assignment 2 COMP1230 (Advanced Web Programming) COMP1230 - Assignment Two Fall 2021: Due date: Nov 07 by 11:59 pm. The objective of the assignment is to use an associative array, iterations,...

1 answer below »
If the assignment asks to put the student name and id then:Name: Viet Long CaoStudent ID: 101245181


Assignment 2 COMP1230 (Advanced Web Programming) COMP1230 - Assignment Two Fall 2021: Due date: Nov 07 by 11:59 pm. The objective of the assignment is to use an associative array, iterations, conditional statements and user-defined functions. The data.inc.php (click to download) contains an associative $inventory array that contains several books' information, such as book id, title, author, etc. You are required to create two sets of functions. 1. HTTP request related functions: these functions provide access to client request information such as accessing HTTP parameter, client IP address, request method (post/get), etc. 2. Inventory utility functions: these functions facilitate accessing inventory data (books) List of HTTP request related functions: 1. Write a PHP function to receive two strings and returns a string (parameter value). https://comp1230.gblearn.com/2021/assignments/assignment2/ Function Parameters: • Name of an HTTP request parameter • A default value to replace non-existing parameters. (Optional parameter) Note: The function should handle both get and post requests. Therefore, this function is called when a post or get request is made to the page. • get is my function name. • get(‘param_name’) • get(‘param_name’,’default_value’) Example: HTTP Request: assignment2.php?id=10 HTTP Response: . ------ HTTP Request: assignment2.php?id=10 HTTP Response: ------ HTTP Request:




If user inputs 5 in above form and clicks on submit: HTTP Response: . 2. Write a PHP function to return a string containing the following information in a tabular format. Hint $_SERVER supper global. • The request method is used to access the page. • The timestamp of the start of the request. • The address of the page (if any) which referred the user agent to the current page. • The IP address from which the user is accessing the current page. • The user agent browser information. Note: • Call this function right after your first function, to display information about the request • Make sure to style the table. • Convert timestamp to readable time (as shown in example below) Expected Output: (localhost) your Output will be different. 3. Write a PHP function to create and return an HTML dropdown menu. The function should receive the following three parameters: a. A string - name of the dropdown b. An array - dropdown options c. An optional string parameter to pass the selected option value to this function. Example: If the function is called with following arguments: _menu('category',[‘cat 1’, ‘cat 2’], ‘cat 2’); Dropdown menu will have two items (cat 1 and cat 2), with cat 2 being the selected item. Please note, the first letter of the items are changed to uppercase, to create the value for output. Inventory utility functions: 4. Write a function to return an array of all the categories in $inventory. • Function prototype: function_name (): return array (categories) • Sample return: ['Fiction’, ‘Biographies’] • Call the function you creaed in previous step (3), by passing the returned array (categories) to display the categories in a dropdown menu in the form created in step 1. i.e: $categories = function_name () // call your function above echo _menu('category', $categories); Will produce following dropdown: 5. Write a function to return all the books for the selected category. • Function prototype: function_name (cat_name) : return array (books) • Sample return: • Print the return value in a readable format. 6. Write a function to search for a book in $inventory by category name and book id. • Function prototype: function_name (cat_name,book_id) : return array (book) • Validation requirements: 1. Return the following string "Cannot find the category category_name" if the category does not exist. 2. Return the following string "Cannot find the book" if the book id does not exist. 3. Sample return: function_name('Fiction’,1) 4. Check if the returned value is an array, and pass the returned array to the fuction you will be writing next (in step 7), to print the book information in a tabular format. If you are not planning to complete the next function, just call your function, by passing a category and an id of a book in our inventory and print the returned book array in a readable format. 7. Write a function to print book information in tabular format. • Function prototype: function_name ($book): prints book inforamtion. • Book price: Print prices for all book types (Paper Back, Hard Cover and Kobo eBook) • Suppose the sale price is not zero print both original price (o_price) and sale price (s_price). Review the following Output for style-related detail. • Sample output: Rubric: • Function 1: 10 marks • Function 2: 15 marks • Function 3: 15 marks • Function 4: 10 marks • Function 5: 10 marks • Function 6: 20 marks • Function 7: 20 marks ➢ Overall functionality 50% ➢ Logic, efficiency, reusability 30% ➢ Naming convention, documentation (valuable comments included in code), readability (spacing/indentation) 20% When you lose marks: 1. Create only one file named assignment2.php in addition to the data file provided. 2. Misspelled file name (i.e assingmnet2.php) (-2 mark deduction) 3. You must include the data.inc.php file in your assignment two file (You will receive a grade of zero if this is ignored) 4. The Output of your assignment must be valid HTML5. (Add the validation script before closing body tag). (Invalid HTML -10) 5. Make sure to include (You will receive a grade of zero if this is ignored) Submission Guidelines: • Upload the two files (assignment2.php and data.inc.php) to the following directory in your GBLearn account comp1230/assignments/assignment2/ • Login to my.gblearn.com and ONLY submit your assignment2.php • Follow the naming convention and have meaningful names for your variables and function. • Apply proper indentation and space before and after operators for readability. • Removing unnecessary/unrelated code & comments. • Add necessary comments to summarize your code or to explain the programmer's intent. • Your work will not be marked if your GBLearn account is not setup • Please Make sure to: • Grant, both of your instructors, access to preview content of your GBLearn account, by adding them to the instructors list on my.gblearn.com • Create comp1230 directory structure (specified on Blackboard) • Update your GBLearn profile page (public_html/index.html) 1. to include a relative link to the comp1230 directory in your account 2. to show a picture of yourself o to include a brief Bio about yourself comp1230-week025-1xof3o0w.ppt 2 WEEK COMP1230 * Advanced Web Programming PHP/MYSQL Objectives 1. Explain how PHP is embedded within an HTML document. 2. Distinguish between PHP statements and comments. 3. Describe these PHP data types: integer, double, Boolean, NULL and string. 4. Rules for creating a PHP variable name. 5. Declaring variable and assigning a value to it. 6. Review the use of superglobals $_GET and $_POST arrays 7. Describe the use of echo statement 8. Describe the rules for evaluating an arithmetic expression, including order of precedence and the use of parentheses. 9. Review some of the built-in functions 10. Introduction to filtering & sanitizing data 11. Built-in functions that pass control 12. Arrays A PHP file that includes HTML and embedded PHP Murach's PHP and MySQL (3rd Ed.) © 2017, Mike Murach & Associates, Inc. C2, Slide * © 2017, Mike Murach & Associates, Inc. The PHP file displayed in a browser Murach's PHP and MySQL (3rd Ed.) © 2017, Mike Murach & Associates, Inc. C2, Slide * © 2017, Mike Murach & Associates, Inc. PHP code: comments and statements Another way to code single-line comments # calculate the discount $discount_percent = .20; # 20% discount Murach's PHP and MySQL (3rd Ed.) © 2017, Mike Murach & Associates, Inc. C2, Slide * © 2017, Mike Murach & Associates, Inc. Syntax rules PHP statements end with a semicolon. PHP ignores extra whitespace in statements. Murach's PHP and MySQL (3rd Ed.) © 2017, Mike Murach & Associates, Inc. C2, Slide * © 2017, Mike Murach & Associates, Inc. PHP data types integer double boolean string array Object NULL Murach's PHP and MySQL (3rd Ed.) © 2017, Mike Murach & Associates, Inc. C2, Slide * © 2017, Mike Murach & Associates, Inc. Integer values (whole numbers) 15 // an integer -21 // a negative integer Double values (numbers with decimal
Answered 1 days AfterNov 02, 2021

Answer To: Assignment 2 COMP1230 (Advanced Web Programming) COMP1230 - Assignment Two Fall 2021: Due date: Nov...

Shubham Kumar answered on Nov 03 2021
114 Votes
assignment2/assignment2.php

require("data.inc.php");
//HTTP Request Related Function :
function get($variable, $default='1234') {
if(isset($_GET[$variable]
))
return $_GET[$variable];
else if(isset($_POST[$variable]))
return $_POST[$variable];
else
return $default;
}
function getRequestInformation() {
//we get all the required information from the $_SERVER array, and then display it in tabular format
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "
Requested Method".$_SERVER['REQUEST_METHOD']."
Access Time".date('m/d/Y H:i:s', $_SERVER['REQUEST_TIME'])."
Referred Url".$_SERVER['HTTP_REFERER']."
Client IP Address".$_SERVER['REMOTE_ADDR']."
User Agent".$_SERVER['HTTP_USER_AGENT']."

";
}
function _menu($title, $values, $selected = "assignment") {
//The return string stores the entire HTML Code for the drop down menu
$returnString = "
";
return $returnString;
}
//Inventory Utility Functions :
function getCategories() {
global $inventory;
$array = [];
//iterate over the associative array and push the category names to the empty array;
foreach($inventory as $key=>$value) {
array_push($array, $key);
}
//call the _menu method which generates a drop...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here