Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- </head>
- <body>
- <style>
- body{background: #C5D0E6}
- input[type="text"],input[type="number"]{
- height: 40px;
- font-size: 150%;
- text-align: center;}
- .divFather{
- background: yellow;
- display:inline-block;
- border:5px solid black;}
- .divСhild{
- background: #C5D0E6;
- border-bottom: 2px solid black;
- text-align: center;}
- .search{padding: 5px;}
- p{
- font-family: 'Times New Roman', Times, serif; /* Гарнитура текста */
- font-size: 150%; /* Размер шрифта в процентах */
- padding: 10px;
- text-align: center;}
- input.btn{
- display: inline-block;
- color: rgb(4, 4, 4);
- font-weight: 600;
- text-decoration: none;
- user-select: none;
- padding: .5em 2em;
- outline: none;
- border: 4px solid;
- border-radius: 10px;
- transition: 0.9s;}
- input.btn:hover { background: rgba(255,255,255,.9); }
- input.btn:active { background: white; }
- </style>
- <div class = "divFather">
- <div class = "divСhild" ><p>Добавить запись о фильме</p></div>
- <form action method="GET" style="padding:10px;">
- <p>Название: <input name="title_1" type="text"></p>
- <p>Год cоздания: <input name="year_1" type="number"></p>
- <p>Страна: <input name="country_1" type="text"></p>
- <input name="add" class = "btn" type="submit" value="Записать">
- </form>
- </div>
- <div class = "divFather">
- <div class = "divСhild"><p>Найти / изменить запись о фильме</p></div>
- <form action method="GET">
- <div class=search>
- <p>Поиск: <input name="query" type="text"> <input name="querybtn" class = "btn" type="submit"></p>
- </div><hr/>
- </form>
- <form action method="GET" style="padding:10px;">
- <p>Название: <input name="title_2" type="text"></p>
- <p>Год cоздания: <input name="year_2" type="number"></p>
- <p>Страна: <input name="country_2" type="text"></p>
- <input name="change" class = "btn" type="submit" value="Изменить">
- </form>
- </div>
- <br/><hr/>
- </body>
- </html>
- <?php
- $Red150 = "<br/><span style='color: red; font-size: 150%;'>";
- $Blue150 = "<br/><span style='color: blue;font-size: 150%;'>";
- $Green200 = "<span style='color: #355E3B; font-size: 200%;'>";
- $Green150 = "<span style='color: green; font-size: 150%;'>";
- $SpanEX = "</span>";
- function writeToFile($title, $year, $country){
- global $Blue150;
- global $SpanEX;
- global $Green200;
- $fp = fopen("data.txt", "a");
- $line = $title.', '.$year.', '.$country;
- fwrite($fp, $line);
- echo $Blue150."В файл записано ".$SpanEX.$Green200.$line.$SpanEX;
- fclose($fp);
- }
- function search($title){
- global $Green200;
- global $SpanEX;
- global $Red150;
- $data = file("data.txt");
- $i = 0;
- foreach($data as $d){
- preg_match("/".$title."/", $d, $matches);
- if(isset($matches[0])){
- setcookie("queryName", $matches[0]);
- setcookie("queryItem", $i);
- $line = $data[$i];
- cooc($line, 0, "title_2");
- cooc($line, 1, "year_2");
- cooc($line, 2, "country_2");
- echo $Green200."Найдена запись: ".$d.$SpanEX."<br/>";
- return;
- }
- $i++;
- }
- setcookie("title_2", null);
- setcookie("year_2", null);
- setcookie("country_2", null);
- echo $Red150."Запись: Не найдена".$SpanEX."<br/>";
- }
- function edit(){
- global $Blue150;
- global $SpanEX;
- $data = file("data.txt");
- $line = $data[$_COOKIE["queryItem"]];
- if (!empty($_GET["title_2"])) $title_2 = $_GET["title_2"];
- else $title_2 = $_COOKIE["title_2"];
- if (!empty($_GET["year_2"])) $year_2 = $_GET["year_2"];
- else $year_2 = $_COOKIE["year_2"];
- if (!empty($_GET["country_2"])) $country_2 = $_GET["country_2"]."\n";
- else $country_2 = $_COOKIE["country_2"];
- $data[$_COOKIE["queryItem"]] = $title_2.", ".$year_2.", ".$country_2;
- $fp = fopen("data.txt", "w");
- fwrite($fp, implode("", $data)."\n");
- fclose($fp);
- echo $Blue150."Строка ".$line." изменена на ".$data[$_COOKIE["queryItem"]].$SpanEX;
- }
- function cooc($str, $num, $name){
- $Arr = explode(", ", $str);
- setcookie("$name", $Arr[$num]);
- }
- //ДОБАВИТЬ
- if(isset($_GET['add'])){
- if (!empty($_GET["title_1"])&&!empty($_GET["year_1"])&&!empty($_GET["country_1"])){
- writeToFile($_GET["title_1"], $_GET["year_1"], $_GET["country_1"]);
- }
- else echo $Red150."Перед отправкой нужно заполнить все поля!".$SpanEX;
- }
- //НАЙТИ
- if(isset($_GET['querybtn'])){
- if (!empty($_GET["query"])) search($_GET["query"]);
- else {
- echo $Red150."Вначале введите что вы ищите".$SpanEX;
- setcookie("queryName", null);
- setcookie("queryItem", null);
- setcookie("title_2", null);
- setcookie("year_2", null);
- setcookie("country_2", null);
- }
- }
- //ИЗМЕНИТЬ
- if(isset($_GET['change'])){
- //edit();
- if (isset($_COOKIE["queryName"])){
- if (empty($_GET["title_2"])&&empty($_GET["year_2"])&&empty($_GET["country_2"])) echo $Red150."Не изменено!".$SpanEX;
- else{
- if (!empty($_GET["title_2"])) echo $Green150."Название изменено!".$SpanEX."<br/>";
- if (!empty($_GET["year_2"])) echo $Green150."Год изменен!".$SpanEX."<br/>";
- if (!empty($_GET["country_2"])) echo $Green150."Страна изменена!".$SpanEX."<br/>";
- edit();
- }
- }
- else echo $Red150."Вначале введите что вы ищите".$SpanEX;
- }
- ?>
Add Comment
Please, Sign In to add comment