blob: c07dd5e976de60395183aa94e834268a095fbab7 [file] [log] [blame]
Marc Kupietzd871d882023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
3
4class User
5{
Marc Kupietz3417c882023-03-07 12:03:21 +01006 public $username;
7 public $first_name;
8 public $last_name;
9 public $organization;
10 public $user_hash;
11 public $password;
12 public $street;
13 public $zip;
14 public $city;
15 public $country;
16 public $email;
17 public $phone;
18 public bool $eula_signed;
19 public bool $privacy_policy_signed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010020 public bool $author;
21 public $accepted_paper_id;
22 public $participation_confirmed;
23 public $participation_confirmed_at;
24 public bool $student;
25 public bool $conference_dinner;
26 public $total_costs;
Marc Kupietz3417c882023-03-07 12:03:21 +010027
28 function __construct()
29 {
30 $this->username = "";
31 $this->first_name = "";
32 $this->last_name = "";
33 $this->email = "";
34 $this->organization = "";
35 $this->user_hash = "";
36 $this->password = "";
37 $this->city = "";
38 $this->country = "";
39 $this->zip = "";
40 $this->street = "";
41 $this->phone = "";
42 $this->eula_signed = false;
43 $this->privacy_policy_signed = false;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010044 $this->author = false;
45 $this->accepted_paper_id = "";
46 $this->participation_confirmed = false;
47 $this->participation_confirmed_at = "";
48 $this->student = false;
49 $this->conference_dinner = false;
50 $this->total_costs = 0;
Marc Kupietz3417c882023-03-07 12:03:21 +010051 }
52
53 function __construct1(object $data)
54 {
55 foreach ($data as $key => $value) {
56 if (array_key_exists($key, (array) $this))
57 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010058 }
Marc Kupietz3417c882023-03-07 12:03:21 +010059 if (isset($data->password)) $this->set_password($data->password);
60 }
Marc Kupietzd871d882023-03-05 18:34:16 +010061
Marc Kupietz3417c882023-03-07 12:03:21 +010062 function init_from_object(object $data)
63 {
64 foreach ($data as $key => $value) {
65 if (array_key_exists($key, (array) $this))
66 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010067 }
Marc Kupietz3417c882023-03-07 12:03:21 +010068 if (isset($data->password)) $this->set_password($data->password);
69 }
Marc Kupietza57befa2023-03-06 21:39:23 +010070
Marc Kupietz3417c882023-03-07 12:03:21 +010071 function init_from_array(array $data)
72 {
73 foreach ($data as $key => $value) {
74 if (array_key_exists($key, (array) $this)) {
75 if (is_bool(gettype($this->{$key})) && is_string($value))
76 $this->{$key} = !empty($value);
77 else
78 $this->{$key} = $value;
79 }
80 }
81 if (!empty($data["password"])) $this->set_password($data["password"]);
82 }
83
Marc Kupietz3417c882023-03-07 12:03:21 +010084
85 function set_password(string $password)
86 {
87 include 'config.php';
88 if ($ENCRYPT_PASSWORDS) {
89 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
90 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
91 } else {
92 $this->user_hash = "{CLEAR}" . $password;
93 }
94 $this->password = $this->user_hash;
95 }
96
97 function to_string()
98 {
99 $tmp_user = $this;
100 $tmp_user->password = "***";
101 $tmp_user->user_hash = "***";
102 return json_encode($tmp_user);
103 }
104
105 function backup_in_session()
106 {
107 global $_SESSION;
108 foreach ($this as $key => $value) {
109 $_SESSION[$key] = $value;
110 }
111 }
112
113 function to_table() {
114 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
115 foreach ($this as $key => $value) {
116 if ($key != "password" && $key != "user_hash" && !empty($value)) {
117 if (is_bool($value)) {
118 if ($value) $value = "yes";
119 else $value = "no";
Marc Kupietzd871d882023-03-05 18:34:16 +0100120 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100121 $value = str_replace("\r\n", "<br>", $value);
122 $key = str_replace("_", " ", ucfirst($key));
123 $table .= " <tr>
124 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
125 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
126 </tr>\n";
127 }
Marc Kupietzd871d882023-03-05 18:34:16 +0100128 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100129 $table .= "</table>";
130 return $table;
131 }
132}