blob: e7efc44c1fe99cc3ffb10b7bced2617657bf6a44 [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 Kupietz145f5b92023-03-09 20:39:31 +010035 public float $total_due;
Marc Kupietz49f677c2023-03-10 08:29:41 +010036 public $invoice;
Marc Kupietz7d728fe2023-03-28 17:32:18 +020037 public bool $presentation_confirmed;
Marc Kupietz03146622023-03-07 12:03:21 +010038
39 function __construct()
40 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010041 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010042 $this->username = "";
Marc Kupietz144d82e2023-03-26 15:55:42 +020043 $this->title = "";
Marc Kupietz03146622023-03-07 12:03:21 +010044 $this->first_name = "";
45 $this->last_name = "";
46 $this->email = "";
47 $this->organization = "";
48 $this->user_hash = "";
49 $this->password = "";
50 $this->city = "";
51 $this->country = "";
52 $this->zip = "";
53 $this->street = "";
54 $this->phone = "";
55 $this->eula_signed = false;
56 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010057 $this->author = false;
58 $this->accepted_paper_id = "";
59 $this->participation_confirmed = false;
60 $this->participation_confirmed_at = "";
61 $this->student = false;
62 $this->conference_dinner = false;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010063 $this->vegetarian_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010064 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
65 $this->earlybird_registration = false;
Marc Kupietz22b2ca22023-03-28 17:28:44 +020066 $this->lunch_day_1 = "";
67 $this->lunch_day_2 = "";
68 $this->lunch_day_3 = "";
Marc Kupietz145f5b92023-03-09 20:39:31 +010069 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010070 $this->invoice = "";
Marc Kupietz7d728fe2023-03-28 17:32:18 +020071 $this->presentation_confirmed = false;
Marc Kupietz03146622023-03-07 12:03:21 +010072 }
73
Marc Kupietz7d728fe2023-03-28 17:32:18 +020074 function set_name_and_paper_id($first_name, $last_name, $paper_id): User
75 {
76 $this->first_name = $first_name;
77 $this->last_name = $last_name;
78 $this->accepted_paper_id = $paper_id;
79 return $this;
80 }
81
82 function set_email_and_paper_id($email, $paper_id): User
83 {
84 $this->email = $email;
85 $this->accepted_paper_id = $paper_id;
86 return $this;
87 }
Marc Kupietz03146622023-03-07 12:03:21 +010088 function __construct1(object $data)
89 {
90 foreach ($data as $key => $value) {
91 if (array_key_exists($key, (array) $this))
92 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010093 }
Marc Kupietz03146622023-03-07 12:03:21 +010094 if (isset($data->password)) $this->set_password($data->password);
95 }
Marc Kupietz0215a442023-03-05 18:34:16 +010096
Marc Kupietz03146622023-03-07 12:03:21 +010097 function init_from_object(object $data)
98 {
99 foreach ($data as $key => $value) {
100 if (array_key_exists($key, (array) $this))
101 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100102 }
Marc Kupietz03146622023-03-07 12:03:21 +0100103 if (isset($data->password)) $this->set_password($data->password);
104 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100105
Marc Kupietz03146622023-03-07 12:03:21 +0100106 function init_from_array(array $data)
107 {
108 foreach ($data as $key => $value) {
109 if (array_key_exists($key, (array) $this)) {
110 if (is_bool(gettype($this->{$key})) && is_string($value))
111 $this->{$key} = !empty($value);
112 else
113 $this->{$key} = $value;
114 }
115 }
116 if (!empty($data["password"])) $this->set_password($data["password"]);
117 }
118
Marc Kupietz03146622023-03-07 12:03:21 +0100119
120 function set_password(string $password)
121 {
122 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100123 if ($CONFERENCE_REGISTRATION) {
124 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +0100125 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
126 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100127 if ($ENCRYPT_PASSWORDS) {
128 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
129 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
130 } else {
131 $this->user_hash = "{CLEAR}" . $password;
132 }
133 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100134 }
Marc Kupietz03146622023-03-07 12:03:21 +0100135 }
136
137 function to_string()
138 {
139 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100140 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100141 $tmp_user->password = "***";
142 $tmp_user->user_hash = "***";
143 return json_encode($tmp_user);
144 }
145
146 function backup_in_session()
147 {
148 global $_SESSION;
149 foreach ($this as $key => $value) {
150 $_SESSION[$key] = $value;
151 }
152 }
153
154 function to_table() {
155 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
156 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100157 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100158 if (is_bool($value)) {
159 if ($value) $value = "yes";
160 else $value = "no";
Marc Kupietz145f5b92023-03-09 20:39:31 +0100161 } elseif(is_float($value)) {
162 $key .= " €";
Marc Kupietzfaa2bd12023-03-21 17:47:41 +0100163 $value = number_format($value, 2, '.', ' ');
Marc Kupietz0215a442023-03-05 18:34:16 +0100164 }
Marc Kupietz03146622023-03-07 12:03:21 +0100165 $value = str_replace("\r\n", "<br>", $value);
166 $key = str_replace("_", " ", ucfirst($key));
167 $table .= " <tr>
168 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
169 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
170 </tr>\n";
171 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100172 }
Marc Kupietz03146622023-03-07 12:03:21 +0100173 $table .= "</table>";
174 return $table;
175 }
176}