blob: 2341eb0c49fdc91b062e2d23330f24e8dbb6fab3 [file] [log] [blame]
Marc Kupietz0215a442023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +01003include_once 'util.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;
9 public $first_name;
10 public $last_name;
11 public $organization;
12 public $user_hash;
13 public $password;
14 public $street;
15 public $zip;
16 public $city;
17 public $country;
18 public $email;
19 public $phone;
20 public bool $eula_signed;
21 public bool $privacy_policy_signed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010022 public bool $author;
23 public $accepted_paper_id;
Marc Kupietz145f5b92023-03-09 20:39:31 +010024 public bool $participation_confirmed;
Marc Kupietzcdf29572023-03-09 08:14:12 +010025 public $participation_confirmed_at;
26 public bool $student;
27 public bool $conference_dinner;
Marc Kupietz49f677c2023-03-10 08:29:41 +010028 public $registered_at;
29 public bool $earlybird_registration;
Marc Kupietz145f5b92023-03-09 20:39:31 +010030 public float $total_due;
Marc Kupietz49f677c2023-03-10 08:29:41 +010031 public $invoice;
Marc Kupietz03146622023-03-07 12:03:21 +010032
33 function __construct()
34 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010035 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010036 $this->username = "";
37 $this->first_name = "";
38 $this->last_name = "";
39 $this->email = "";
40 $this->organization = "";
41 $this->user_hash = "";
42 $this->password = "";
43 $this->city = "";
44 $this->country = "";
45 $this->zip = "";
46 $this->street = "";
47 $this->phone = "";
48 $this->eula_signed = false;
49 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010050 $this->author = false;
51 $this->accepted_paper_id = "";
52 $this->participation_confirmed = false;
53 $this->participation_confirmed_at = "";
54 $this->student = false;
55 $this->conference_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010056 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
57 $this->earlybird_registration = false;
Marc Kupietz145f5b92023-03-09 20:39:31 +010058 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010059 $this->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +010060 }
61
62 function __construct1(object $data)
63 {
64 foreach ($data as $key => $value) {
65 if (array_key_exists($key, (array) $this))
66 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010067 }
Marc Kupietz03146622023-03-07 12:03:21 +010068 if (isset($data->password)) $this->set_password($data->password);
69 }
Marc Kupietz0215a442023-03-05 18:34:16 +010070
Marc Kupietz03146622023-03-07 12:03:21 +010071 function init_from_object(object $data)
72 {
73 foreach ($data as $key => $value) {
74 if (array_key_exists($key, (array) $this))
75 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010076 }
Marc Kupietz03146622023-03-07 12:03:21 +010077 if (isset($data->password)) $this->set_password($data->password);
78 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +010079
Marc Kupietz03146622023-03-07 12:03:21 +010080 function init_from_array(array $data)
81 {
82 foreach ($data as $key => $value) {
83 if (array_key_exists($key, (array) $this)) {
84 if (is_bool(gettype($this->{$key})) && is_string($value))
85 $this->{$key} = !empty($value);
86 else
87 $this->{$key} = $value;
88 }
89 }
90 if (!empty($data["password"])) $this->set_password($data["password"]);
91 }
92
Marc Kupietz03146622023-03-07 12:03:21 +010093
94 function set_password(string $password)
95 {
96 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +010097 if ($CONFERENCE_REGISTRATION) {
98 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +010099 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
100 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100101 if ($ENCRYPT_PASSWORDS) {
102 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
103 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
104 } else {
105 $this->user_hash = "{CLEAR}" . $password;
106 }
107 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100108 }
Marc Kupietz03146622023-03-07 12:03:21 +0100109 }
110
111 function to_string()
112 {
113 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100114 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100115 $tmp_user->password = "***";
116 $tmp_user->user_hash = "***";
117 return json_encode($tmp_user);
118 }
119
120 function backup_in_session()
121 {
122 global $_SESSION;
123 foreach ($this as $key => $value) {
124 $_SESSION[$key] = $value;
125 }
126 }
127
128 function to_table() {
129 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
130 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100131 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100132 if (is_bool($value)) {
133 if ($value) $value = "yes";
134 else $value = "no";
Marc Kupietz145f5b92023-03-09 20:39:31 +0100135 } elseif(is_float($value)) {
136 $key .= " €";
Marc Kupietz0215a442023-03-05 18:34:16 +0100137 }
Marc Kupietz03146622023-03-07 12:03:21 +0100138 $value = str_replace("\r\n", "<br>", $value);
139 $key = str_replace("_", " ", ucfirst($key));
140 $table .= " <tr>
141 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
142 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
143 </tr>\n";
144 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100145 }
Marc Kupietz03146622023-03-07 12:03:21 +0100146 $table .= "</table>";
147 return $table;
148 }
149}