blob: 9fe489998be31a223b6ca44fb52a029b46f6d0d2 [file] [log] [blame]
Marc Kupietz0215a442023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
Marc Kupietzbaf8d912023-03-15 09:13:03 +01003include_once 'utils.php';
Marc Kupietz0215a442023-03-05 18:34:16 +01004
5class User
6{
Marc Kupietz49f677c2023-03-10 08:29:41 +01007 public $id;
Marc Kupietz03146622023-03-07 12:03:21 +01008 public $username;
Marc Kupietz144d82e2023-03-26 15:55:42 +02009 public $title;
Marc Kupietz03146622023-03-07 12:03:21 +010010 public $first_name;
11 public $last_name;
12 public $organization;
13 public $user_hash;
14 public $password;
15 public $street;
16 public $zip;
17 public $city;
18 public $country;
19 public $email;
20 public $phone;
21 public bool $eula_signed;
22 public bool $privacy_policy_signed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010023 public bool $author;
24 public $accepted_paper_id;
Marc Kupietz145f5b92023-03-09 20:39:31 +010025 public bool $participation_confirmed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010026 public $participation_confirmed_at;
27 public bool $student;
28 public bool $conference_dinner;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010029 public bool $vegetarian_dinner;
Marc Kupietz49f677c2023-03-10 08:29:41 +010030 public $registered_at;
31 public bool $earlybird_registration;
Marc Kupietz79eaa0b2023-03-16 17:33:43 +010032 public $lunch_day_1;
33 public $lunch_day_2;
34 public $lunch_day_3;
Marc Kupietz8b80c7a2023-03-28 21:41:39 +020035 public bool $excursion;
Marc Kupietz145f5b92023-03-09 20:39:31 +010036 public float $total_due;
Marc Kupietz49f677c2023-03-10 08:29:41 +010037 public $invoice;
Marc Kupietz7d728fe2023-03-28 17:32:18 +020038 public bool $presentation_confirmed;
Marc Kupietz03146622023-03-07 12:03:21 +010039
40 function __construct()
41 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010042 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010043 $this->username = "";
Marc Kupietz144d82e2023-03-26 15:55:42 +020044 $this->title = "";
Marc Kupietz03146622023-03-07 12:03:21 +010045 $this->first_name = "";
46 $this->last_name = "";
47 $this->email = "";
48 $this->organization = "";
49 $this->user_hash = "";
50 $this->password = "";
51 $this->city = "";
52 $this->country = "";
53 $this->zip = "";
54 $this->street = "";
55 $this->phone = "";
56 $this->eula_signed = false;
57 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010058 $this->author = false;
59 $this->accepted_paper_id = "";
60 $this->participation_confirmed = false;
61 $this->participation_confirmed_at = "";
62 $this->student = false;
63 $this->conference_dinner = false;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010064 $this->vegetarian_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010065 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
66 $this->earlybird_registration = false;
Marc Kupietz22b2ca22023-03-28 17:28:44 +020067 $this->lunch_day_1 = "";
68 $this->lunch_day_2 = "";
69 $this->lunch_day_3 = "";
Marc Kupietz8b80c7a2023-03-28 21:41:39 +020070 $this->excursion = false;
Marc Kupietz145f5b92023-03-09 20:39:31 +010071 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010072 $this->invoice = "";
Marc Kupietz7d728fe2023-03-28 17:32:18 +020073 $this->presentation_confirmed = false;
Marc Kupietz03146622023-03-07 12:03:21 +010074 }
75
Marc Kupietz7d728fe2023-03-28 17:32:18 +020076 function set_name_and_paper_id($first_name, $last_name, $paper_id): User
77 {
78 $this->first_name = $first_name;
79 $this->last_name = $last_name;
80 $this->accepted_paper_id = $paper_id;
81 return $this;
82 }
83
84 function set_email_and_paper_id($email, $paper_id): User
85 {
86 $this->email = $email;
87 $this->accepted_paper_id = $paper_id;
88 return $this;
89 }
Marc Kupietz03146622023-03-07 12:03:21 +010090 function __construct1(object $data)
91 {
92 foreach ($data as $key => $value) {
93 if (array_key_exists($key, (array) $this))
94 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010095 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +020096 if (isset($data->password))
97 $this->set_password($data->password);
Marc Kupietz03146622023-03-07 12:03:21 +010098 }
Marc Kupietz0215a442023-03-05 18:34:16 +010099
Marc Kupietz03146622023-03-07 12:03:21 +0100100 function init_from_object(object $data)
101 {
102 foreach ($data as $key => $value) {
103 if (array_key_exists($key, (array) $this))
104 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100105 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200106 if (isset($data->password))
107 $this->set_password($data->password);
Marc Kupietz03146622023-03-07 12:03:21 +0100108 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100109
Marc Kupietz03146622023-03-07 12:03:21 +0100110 function init_from_array(array $data)
111 {
112 foreach ($data as $key => $value) {
113 if (array_key_exists($key, (array) $this)) {
114 if (is_bool(gettype($this->{$key})) && is_string($value))
115 $this->{$key} = !empty($value);
116 else
117 $this->{$key} = $value;
118 }
119 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200120 if (!empty($data["password"]))
121 $this->set_password($data["password"]);
Marc Kupietz03146622023-03-07 12:03:21 +0100122 }
123
Marc Kupietz03146622023-03-07 12:03:21 +0100124
125 function set_password(string $password)
126 {
127 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100128 if ($CONFERENCE_REGISTRATION) {
129 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +0100130 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
131 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100132 if ($ENCRYPT_PASSWORDS) {
133 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
134 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
135 } else {
136 $this->user_hash = "{CLEAR}" . $password;
137 }
138 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100139 }
Marc Kupietz03146622023-03-07 12:03:21 +0100140 }
141
142 function to_string()
143 {
144 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100145 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100146 $tmp_user->password = "***";
147 $tmp_user->user_hash = "***";
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200148 return json_encode($tmp_user);
Marc Kupietz03146622023-03-07 12:03:21 +0100149 }
150
151 function backup_in_session()
152 {
153 global $_SESSION;
154 foreach ($this as $key => $value) {
155 $_SESSION[$key] = $value;
156 }
157 }
158
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200159 function to_table()
160 {
Marc Kupietz03146622023-03-07 12:03:21 +0100161 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
162 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100163 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100164 if (is_bool($value)) {
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200165 if ($value)
166 $value = "yes";
167 else
168 $value = "no";
169 } elseif (is_float($value)) {
Marc Kupietz145f5b92023-03-09 20:39:31 +0100170 $key .= " €";
Marc Kupietzfaa2bd12023-03-21 17:47:41 +0100171 $value = number_format($value, 2, '.', ' ');
Marc Kupietz0215a442023-03-05 18:34:16 +0100172 }
Marc Kupietz03146622023-03-07 12:03:21 +0100173 $value = str_replace("\r\n", "<br>", $value);
174 $key = str_replace("_", " ", ucfirst($key));
175 $table .= " <tr>
176 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
177 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
178 </tr>\n";
179 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100180 }
Marc Kupietz03146622023-03-07 12:03:21 +0100181 $table .= "</table>";
182 return $table;
183 }
184}