fevzi02

Lenur4LAB.php

Apr 7th, 2022 (edited)
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8">
  5.     </head>
  6.     <body>
  7.         <style>
  8.             body{background: #C5D0E6}
  9.  
  10.             input[type="text"],input[type="number"]{
  11.                 height: 40px;
  12.                 font-size: 150%;
  13.                 text-align: center;}
  14.  
  15.             .divFather{
  16.                 background: yellow;
  17.                 display:inline-block;
  18.                 border:5px solid black;}
  19.  
  20.             .divСhild{
  21.                 background: #C5D0E6;
  22.                 border-bottom: 2px solid black;
  23.                 text-align: center;}
  24.  
  25.             .search{padding: 5px;}
  26.  
  27.             p{
  28.                 font-family: 'Times New Roman', Times, serif; /* Гарнитура текста */
  29.                 font-size: 150%; /* Размер шрифта в процентах */
  30.                 padding: 10px;
  31.                 text-align: center;}
  32.  
  33.             input.btn{
  34.                 display: inline-block;
  35.                 color: rgb(4, 4, 4);
  36.                 font-weight: 600;
  37.                 text-decoration: none;
  38.                 user-select: none;
  39.                 padding: .5em 2em;
  40.                 outline: none;
  41.                 border: 4px solid;
  42.                 border-radius: 10px;
  43.                 transition: 0.9s;}
  44.  
  45.             input.btn:hover { background: rgba(255,255,255,.9); }
  46.  
  47.             input.btn:active { background: white; }
  48.         </style>
  49.  
  50.         <div class = "divFather">
  51.             <div class = "divСhild" ><p>Добавить запись о фильме</p></div>
  52.             <form action method="GET" style="padding:10px;">
  53.                 <p>Название: <input name="title_1" type="text"></p>
  54.                 <p>Год cоздания: <input name="year_1"  type="number"></p>
  55.                 <p>Страна: <input name="country_1" type="text"></p>
  56.                 <input name="add" class = "btn" type="submit" value="Записать">
  57.             </form>
  58.         </div>
  59.  
  60.         <div class = "divFather">
  61.             <div class = "divСhild"><p>Найти / изменить запись о фильме</p></div>
  62.             <form action method="GET">
  63.                 <div class=search>
  64.                     <p>Поиск: <input name="query" type="text"> <input name="querybtn" class = "btn" type="submit"></p>
  65.                 </div><hr/>
  66.             </form>
  67.             <form action method="GET" style="padding:10px;">
  68.                 <p>Название: <input name="title_2" type="text"></p>
  69.                 <p>Год cоздания: <input name="year_2"  type="number"></p>
  70.                 <p>Страна: <input name="country_2" type="text"></p>
  71.                 <input name="change" class = "btn" type="submit" value="Изменить">
  72.             </form>
  73.         </div>
  74.         <br/><hr/>
  75.     </body>
  76. </html>
  77.  
  78. <?php
  79. $Red150 = "<br/><span style='color: red; font-size: 150%;'>";
  80. $Blue150 = "<br/><span style='color: blue;font-size: 150%;'>";
  81. $Green200 = "<span style='color: #355E3B; font-size: 200%;'>";
  82. $Green150 = "<span style='color: green; font-size: 150%;'>";
  83. $SpanEX = "</span>";
  84.  
  85.  
  86. function writeToFile($title, $year, $country){
  87.     global $Blue150;
  88.     global $SpanEX;
  89.     global $Green200;
  90.  
  91.     $fp = fopen("data.txt", "a");
  92.     $line = $title.', '.$year.', '.$country;
  93.     fwrite($fp, $line);
  94.     echo $Blue150."В файл записано ".$SpanEX.$Green200.$line.$SpanEX;
  95.     fclose($fp);
  96. }
  97.  
  98. function search($title){
  99.     global $Green200;
  100.     global $SpanEX;
  101.     global $Red150;
  102.  
  103.     $data = file("data.txt");
  104.     $i = 0;
  105.     foreach($data as $d){
  106.         preg_match("/".$title."/", $d, $matches);
  107.         if(isset($matches[0])){
  108.             setcookie("queryName", $matches[0]);
  109.             setcookie("queryItem", $i);
  110.  
  111.             $line = $data[$i];
  112.             cooc($line, 0, "title_2");
  113.             cooc($line, 1, "year_2");
  114.             cooc($line, 2, "country_2");
  115.             echo $Green200."Найдена запись: ".$d.$SpanEX."<br/>";
  116.             return;
  117.         }
  118.         $i++;
  119.     }
  120.     setcookie("title_2", null);
  121.     setcookie("year_2", null);
  122.     setcookie("country_2", null);
  123.  
  124.     echo $Red150."Запись: Не найдена".$SpanEX."<br/>";
  125. }
  126.  
  127. function edit(){
  128.     global $Blue150;
  129.     global $SpanEX;
  130.  
  131.     $data = file("data.txt");
  132.     $line = $data[$_COOKIE["queryItem"]];
  133.  
  134.     if (!empty($_GET["title_2"])) $title_2 = $_GET["title_2"];
  135.     else $title_2 = $_COOKIE["title_2"];
  136.  
  137.     if (!empty($_GET["year_2"])) $year_2 = $_GET["year_2"];
  138.     else $year_2 = $_COOKIE["year_2"];
  139.  
  140.     if (!empty($_GET["country_2"])) $country_2 = $_GET["country_2"]."\n";
  141.     else $country_2 = $_COOKIE["country_2"];
  142.  
  143.  
  144.     $data[$_COOKIE["queryItem"]] = $title_2.", ".$year_2.", ".$country_2;
  145.  
  146.     $fp = fopen("data.txt", "w");
  147.     fwrite($fp, implode("", $data)."\n");
  148.     fclose($fp);
  149.  
  150.     echo $Blue150."Строка ".$line." изменена на ".$data[$_COOKIE["queryItem"]].$SpanEX;
  151.  
  152. }
  153.  
  154. function cooc($str, $num, $name){
  155.     $Arr = explode(", ", $str);
  156.     setcookie("$name", $Arr[$num]);
  157. }
  158.  
  159. //ДОБАВИТЬ
  160. if(isset($_GET['add'])){
  161.     if (!empty($_GET["title_1"])&&!empty($_GET["year_1"])&&!empty($_GET["country_1"])){
  162.         writeToFile($_GET["title_1"], $_GET["year_1"], $_GET["country_1"]);
  163.     }
  164.     else echo $Red150."Перед отправкой нужно заполнить все поля!".$SpanEX;
  165.  
  166. }
  167.  
  168. //НАЙТИ
  169. if(isset($_GET['querybtn'])){
  170.     if (!empty($_GET["query"])) search($_GET["query"]);
  171.     else {
  172.         echo $Red150."Вначале введите что вы ищите".$SpanEX;
  173.         setcookie("queryName", null);
  174.         setcookie("queryItem", null);
  175.         setcookie("title_2", null);
  176.         setcookie("year_2", null);
  177.         setcookie("country_2", null);
  178.     }
  179. }
  180.  
  181.  
  182. //ИЗМЕНИТЬ
  183. if(isset($_GET['change'])){
  184.     //edit();
  185.     if (isset($_COOKIE["queryName"])){
  186.         if (empty($_GET["title_2"])&&empty($_GET["year_2"])&&empty($_GET["country_2"])) echo $Red150."Не изменено!".$SpanEX;
  187.         else{
  188.             if (!empty($_GET["title_2"])) echo $Green150."Название изменено!".$SpanEX."<br/>";
  189.             if (!empty($_GET["year_2"])) echo $Green150."Год изменен!".$SpanEX."<br/>";
  190.             if (!empty($_GET["country_2"])) echo $Green150."Страна изменена!".$SpanEX."<br/>";
  191.  
  192.             edit();
  193.         }
  194.     }
  195.     else echo $Red150."Вначале введите что вы ищите".$SpanEX;
  196. }
  197. ?>
Add Comment
Please, Sign In to add comment