Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.66 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: oliver
  5.  * Date: 21.04.18
  6.  * Time: 16:50
  7.  */
  8.  
  9. require_once "../lib/tpl.php";
  10. $list = "list.html";
  11. $add = "add.html";
  12. $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : "list";
  13. $data_array = [];
  14.  
  15.  
  16. class Person
  17. {
  18.     public $firstName;
  19.     public $lastName;
  20.     public $phone;
  21.  
  22.     public function __construct($firstName, $lastName, $phone)
  23.     {
  24.         $this->firstName = $firstName;
  25.         $this->lastName = $lastName;
  26.         $this->phone = $phone;
  27.     }
  28. }
  29.  
  30. function put_data()
  31. {
  32.     $firstName = $_POST["firstName"];
  33.     $lastName = $_POST["lastName"];
  34.     $phone = $_POST["phone"];
  35.     $file = 'data.txt';
  36.         //"\n" . $firstName . ":" . $lastName . ":" . $phone
  37.     file_put_contents($file, "asdasdasdasdasdasd", FILE_APPEND);
  38.     $data_array = read_item();
  39.     return render_template("main.html", ['$table' => "list.html", '$data_array' => $data_array]);
  40. }
  41.  
  42. function read_item()
  43. {
  44.     $data = file_get_contents("data.txt");
  45.     $lis = explode("\n", $data);
  46.     if ($lis == "") {
  47.     } else {
  48.         foreach ($lis as $value) {
  49.             $personInfo = explode(":", $value);
  50.             list($firstName, $lastName, $phone) = $personInfo;
  51.             $data_array[] = new Person($firstName, $lastName, $phone);
  52.         }
  53.         return $data_array;
  54.     }
  55. }
  56.  
  57.  
  58. if ($cmd == "list") {
  59.     $data_array = read_item();
  60.     print render_template("main.html", ['$table' => $list, '$data_array' => $data_array]);
  61. } elseif ($cmd == "add") {
  62.     print render_template("add.html", ['$table' => $add]);
  63. } elseif ($cmd == "add_all") {
  64.     file_put_contents($file, "asdasdasdasdasdasd", FILE_APPEND);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement