blob: 2cc395c2c7d531f132b0987fd8875f0b2592c00d [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 Kupietz541cb222023-04-14 07:38:05 +020039 public $amount_open;
Marc Kupietz03146622023-03-07 12:03:21 +010040
41 function __construct()
42 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010043 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010044 $this->username = "";
Marc Kupietz144d82e2023-03-26 15:55:42 +020045 $this->title = "";
Marc Kupietz03146622023-03-07 12:03:21 +010046 $this->first_name = "";
47 $this->last_name = "";
48 $this->email = "";
49 $this->organization = "";
50 $this->user_hash = "";
51 $this->password = "";
52 $this->city = "";
53 $this->country = "";
54 $this->zip = "";
55 $this->street = "";
56 $this->phone = "";
57 $this->eula_signed = false;
58 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010059 $this->author = false;
60 $this->accepted_paper_id = "";
61 $this->participation_confirmed = false;
62 $this->participation_confirmed_at = "";
63 $this->student = false;
64 $this->conference_dinner = false;
Marc Kupietz0dbe6b62023-03-21 17:58:11 +010065 $this->vegetarian_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010066 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
67 $this->earlybird_registration = false;
Marc Kupietz22b2ca22023-03-28 17:28:44 +020068 $this->lunch_day_1 = "";
69 $this->lunch_day_2 = "";
70 $this->lunch_day_3 = "";
Marc Kupietz8b80c7a2023-03-28 21:41:39 +020071 $this->excursion = false;
Marc Kupietz145f5b92023-03-09 20:39:31 +010072 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010073 $this->invoice = "";
Marc Kupietz7d728fe2023-03-28 17:32:18 +020074 $this->presentation_confirmed = false;
Marc Kupietz541cb222023-04-14 07:38:05 +020075 $this->amount_open = 0.0;
Marc Kupietz03146622023-03-07 12:03:21 +010076 }
77
Marc Kupietz7d728fe2023-03-28 17:32:18 +020078 function set_name_and_paper_id($first_name, $last_name, $paper_id): User
79 {
80 $this->first_name = $first_name;
81 $this->last_name = $last_name;
82 $this->accepted_paper_id = $paper_id;
83 return $this;
84 }
85
86 function set_email_and_paper_id($email, $paper_id): User
87 {
88 $this->email = $email;
89 $this->accepted_paper_id = $paper_id;
90 return $this;
91 }
Marc Kupietz03146622023-03-07 12:03:21 +010092 function __construct1(object $data)
93 {
94 foreach ($data as $key => $value) {
95 if (array_key_exists($key, (array) $this))
96 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010097 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +020098 if (isset($data->password))
99 $this->set_password($data->password);
Marc Kupietz03146622023-03-07 12:03:21 +0100100 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100101
Marc Kupietz03146622023-03-07 12:03:21 +0100102 function init_from_object(object $data)
103 {
104 foreach ($data as $key => $value) {
105 if (array_key_exists($key, (array) $this))
106 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100107 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200108 if (isset($data->password))
109 $this->set_password($data->password);
Marc Kupietz03146622023-03-07 12:03:21 +0100110 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +0100111
Marc Kupietz03146622023-03-07 12:03:21 +0100112 function init_from_array(array $data)
113 {
114 foreach ($data as $key => $value) {
115 if (array_key_exists($key, (array) $this)) {
116 if (is_bool(gettype($this->{$key})) && is_string($value))
117 $this->{$key} = !empty($value);
118 else
119 $this->{$key} = $value;
120 }
121 }
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200122 if (!empty($data["password"]))
123 $this->set_password($data["password"]);
Marc Kupietz03146622023-03-07 12:03:21 +0100124 }
125
Marc Kupietz03146622023-03-07 12:03:21 +0100126
127 function set_password(string $password)
128 {
129 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100130 if ($CONFERENCE_REGISTRATION) {
131 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +0100132 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
133 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100134 if ($ENCRYPT_PASSWORDS) {
135 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
136 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
137 } else {
138 $this->user_hash = "{CLEAR}" . $password;
139 }
140 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100141 }
Marc Kupietz03146622023-03-07 12:03:21 +0100142 }
143
144 function to_string()
145 {
146 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100147 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100148 $tmp_user->password = "***";
149 $tmp_user->user_hash = "***";
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200150 return json_encode($tmp_user);
Marc Kupietz03146622023-03-07 12:03:21 +0100151 }
152
153 function backup_in_session()
154 {
155 global $_SESSION;
156 foreach ($this as $key => $value) {
157 $_SESSION[$key] = $value;
158 }
159 }
160
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200161 function to_table()
162 {
Marc Kupietz03146622023-03-07 12:03:21 +0100163 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
164 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100165 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100166 if (is_bool($value)) {
Marc Kupietz8b80c7a2023-03-28 21:41:39 +0200167 if ($value)
168 $value = "yes";
169 else
170 $value = "no";
171 } elseif (is_float($value)) {
Marc Kupietz145f5b92023-03-09 20:39:31 +0100172 $key .= " €";
Marc Kupietzfaa2bd12023-03-21 17:47:41 +0100173 $value = number_format($value, 2, '.', ' ');
Marc Kupietz0215a442023-03-05 18:34:16 +0100174 }
Marc Kupietz03146622023-03-07 12:03:21 +0100175 $value = str_replace("\r\n", "<br>", $value);
176 $key = str_replace("_", " ", ucfirst($key));
177 $table .= " <tr>
178 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
179 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
180 </tr>\n";
181 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100182 }
Marc Kupietz03146622023-03-07 12:03:21 +0100183 $table .= "</table>";
184 return $table;
185 }
186}