Commit 9eecc917 by farama

added Lab5

parent bed260af
body {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
form {
background-color: #EFEFEF;
border: 1px solid #333;
margin: auto;
padding: 20px;
width: 420px;
}
label {
display: inline-block;
width: 100px;
}
input, select, textarea {
border: 1px solid darkgrey;
margin: 5px;
padding: 2px;
width: 200px;
}
input:focus, select:focus {
background-color: rgb(221, 203, 238);
border: 1px solid blueviolet;
}
input[type="submit"] {
margin-left: 110px;
}
textarea {
margin-left: 0;
width: 400px;
}
.confirmation
{
width: 460px;
margin: auto;
margin-top: 50px;
background-color: green;
border: 2px solid gray;
padding: 10px;
text-align: left;
border-radius: 20px;
}
.confirmation-text
{
font-family: Arial;
color:white;
font-size: 14px;
margin-top: 20px;
margin-left: 20px;
}
\ No newline at end of file
<!DOCTYPE HTML>
<?php
$file = "text/info.txt";
if($_POST && isset($_POST["file"])){
if(file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
flush(); // Flush system output buffer
readfile($file);
die();
} else {
http_response_code(404);
die();
}
}
if($_POST && isset($_POST["firstname"], $_POST["lastname"], $_POST["salutation"], $_POST["age"], $_POST["email"], $_POST["phone"], $_POST["arrival-date"]))
{
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$salutation = $_POST["salutation"];
$age = $_POST["age"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$arrivalDate = $_POST["arrival-date"];
$middlename = $_POST["middlename"];
$homepage = $_POST["homepage"];
$message = $_POST["message"];
$myarray = array($firstname, $middlename, $lastname, $salutation, $age, $email, $phone, $arrivalDate, $homepage, $message);
$mynames = array("First Name: ", "Middle Name: ", "Last name: ", "Salutation: ", "Age: ", "E-mail: ", "Phone: ", "Arrival Date: ", "Homepage: ", "Message: ");
$totalEntries = '';
$f = fopen($file, 'r');
$cursor = -1;
fseek($f, $cursor, SEEK_END);
$char = fgetc($f);
while ($char === "\n" || $char === "\r") {
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
while ($char !== false && $char !== "\n" && $char !== "\r") {
//$totalEntries = $char . $totalEntries;
$totalEntries = $char;
fseek($f, $cursor--, SEEK_END);
$char = fgetc($f);
}
fclose($f);
$lines = file($file);
// Pop the last item from the array
array_pop($lines);
// Join the array back into a string
$fileg = join('', $lines);
// Write the string back into the file
$file_handle = fopen($file, 'w');
fputs($file_handle, $fileg);
fclose($file_handle);
if(file_exists($file))
{
$handle = fopen($file, "a+") or die("Error");
if($totalEntries != "")
{
fwrite($handle, "\n");
}
for($i = 0; $i < count($myarray)-1; $i++)
{
fwrite($handle, $mynames[$i]);
fwrite($handle, $myarray[$i]);
fwrite($handle, "\n");
}
if($totalEntries != "")
{
$totalEntries = (int)$totalEntries+1;
fwrite($handle, $totalEntries);
} else
{
$totalEntries = 1;
fwrite($handle, $totalEntries);
}
fclose($handle);
}
}
?>
<html>
<head>
<meta charset="UTF-8">
<title>LAB 5</title>
<link rel="stylesheet" href="css/style.css"></link>
</head>
<body>
<form action="index.php" method="POST" id="data">
<label for = "firstname">First name:</label>
<input type = "text" id = "firstname" name = "firstname" required placeholder = "Enter your first name" /><br>
<label for = "middlename">Middle name:</label>
<input type = "text" id = "middlename" name = "middlename" placeholder = "Enter your middle name (optional)" /><br>
<label for = "lastname">Last name:</label>
<input type = "text" id = "lastname" name = "lastname" required placeholder = "Enter your last name" /><br>
<label for = "salutation">Salutation</label>
<input list = "salutation-list" id = "salutation" name = "salutation" required placeholder = "Mr, Ms..." />
<datalist id = "salutation-list">
<option value = "Mr" />
<option value = "Ms" />
<option value = "Mrs" />
<option value = "Sir" />
<option value = "Prof" />
<option value = "Dr" />
</datalist>
<br>
<label for = "age">Age:</label>
<input type = "number" id = "age" name = "age" size = "6" min = "17" max = "99" value = "21" required /><br>
<label for = "email">E-mail:</label>
<input type = "email" id = "email" name = "email" required placeholder = "Enter a valid email address" /><br>
<label for = "phone">Phone:</label>
<input type = "tel" id = "phone" name = "phone" pattern = "[0-9,+]{1,6} [0-9]{3} [0-9]{3}" required placeholder="Number as 000 000 000" /><br>
<label for = "arrival-date">Date of arrival:</label>
<input type = "date" id = "arrival-date" name = "arrival-date" min = "2000-01-01" max = "2019-12-31" required /><br>
<label for = "homepage">Homepage:</label>
<input type = "url" id = "homepage" name = "homepage" placeholder = "Enter your Homepage URL" pattern = "https?://.+" /><br>
<label for = "message">Message:</label>
<textarea type = "message" id = "message" rows="3" cols="20" novalidate></textarea><br>
<input type = "submit" value = "submit" />
</form>
<form action="index.php" method="POST" id="data">
<input type="submit" class="button" name="file" value="Download the registration data" />
</form>
<div class = "confirmation">
<?php
for($i = 0; $i < count($myarray)-1; $i++)
{
echo"<span class = \"confirmation-text\">$mynames[$i]</span>";
echo"<span class = \"confirmation-text\">$myarray[$i]</span>";
echo "<br>";
}
echo"<span class = \"confirmation-text\">Total number entries: $totalEntries</span>";
?>
</div>
</body>
</html>
\ No newline at end of file
<?php
class User
{
public $name, $age;
function __construct($name, $age)
{
$this->name = $name;
$this->age = $age;
}
function getInfo()
{
echo "Имя: $this->name ; Возраст: $this->age <br>";
}
}
$user = new User("Megumin", 16);
$user -> getInfo();
print_r($user);
?>
<html>
<body>
<h1>HI</h1>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment