blob: 642e8941afb22deaf5abc42eaede62fa0d063f65 [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;
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 Kupietz79eaa0b2023-03-16 17:33:43 +010030 public $lunch_day_1;
31 public $lunch_day_2;
32 public $lunch_day_3;
Marc Kupietz145f5b92023-03-09 20:39:31 +010033 public float $total_due;
Marc Kupietz49f677c2023-03-10 08:29:41 +010034 public $invoice;
Marc Kupietz03146622023-03-07 12:03:21 +010035
36 function __construct()
37 {
Marc Kupietz49f677c2023-03-10 08:29:41 +010038 $this->id = "";
Marc Kupietz03146622023-03-07 12:03:21 +010039 $this->username = "";
40 $this->first_name = "";
41 $this->last_name = "";
42 $this->email = "";
43 $this->organization = "";
44 $this->user_hash = "";
45 $this->password = "";
46 $this->city = "";
47 $this->country = "";
48 $this->zip = "";
49 $this->street = "";
50 $this->phone = "";
51 $this->eula_signed = false;
52 $this->privacy_policy_signed = false;
Marc Kupietzcdf29572023-03-09 08:14:12 +010053 $this->author = false;
54 $this->accepted_paper_id = "";
55 $this->participation_confirmed = false;
56 $this->participation_confirmed_at = "";
57 $this->student = false;
58 $this->conference_dinner = false;
Marc Kupietz49f677c2023-03-10 08:29:41 +010059 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
60 $this->earlybird_registration = false;
Marc Kupietz145f5b92023-03-09 20:39:31 +010061 $this->total_due = 0.0;
Marc Kupietz49f677c2023-03-10 08:29:41 +010062 $this->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +010063 }
64
65 function __construct1(object $data)
66 {
67 foreach ($data as $key => $value) {
68 if (array_key_exists($key, (array) $this))
69 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010070 }
Marc Kupietz03146622023-03-07 12:03:21 +010071 if (isset($data->password)) $this->set_password($data->password);
72 }
Marc Kupietz0215a442023-03-05 18:34:16 +010073
Marc Kupietz03146622023-03-07 12:03:21 +010074 function init_from_object(object $data)
75 {
76 foreach ($data as $key => $value) {
77 if (array_key_exists($key, (array) $this))
78 $this->{$key} = $value;
Marc Kupietzade9e3c2023-03-06 21:39:23 +010079 }
Marc Kupietz03146622023-03-07 12:03:21 +010080 if (isset($data->password)) $this->set_password($data->password);
81 }
Marc Kupietzade9e3c2023-03-06 21:39:23 +010082
Marc Kupietz03146622023-03-07 12:03:21 +010083 function init_from_array(array $data)
84 {
85 foreach ($data as $key => $value) {
86 if (array_key_exists($key, (array) $this)) {
87 if (is_bool(gettype($this->{$key})) && is_string($value))
88 $this->{$key} = !empty($value);
89 else
90 $this->{$key} = $value;
91 }
92 }
93 if (!empty($data["password"])) $this->set_password($data["password"]);
94 }
95
Marc Kupietz03146622023-03-07 12:03:21 +010096
97 function set_password(string $password)
98 {
99 include 'config.php';
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100100 if ($CONFERENCE_REGISTRATION) {
101 $this->password = generateRandomString(32);
Marc Kupietz03146622023-03-07 12:03:21 +0100102 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
103 } else {
Marc Kupietz7f5e5272023-03-10 13:54:21 +0100104 if ($ENCRYPT_PASSWORDS) {
105 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
106 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
107 } else {
108 $this->user_hash = "{CLEAR}" . $password;
109 }
110 $this->password = $this->user_hash;
Marc Kupietz03146622023-03-07 12:03:21 +0100111 }
Marc Kupietz03146622023-03-07 12:03:21 +0100112 }
113
114 function to_string()
115 {
116 $tmp_user = $this;
Marc Kupietz49f677c2023-03-10 08:29:41 +0100117 $tmp_user->invoice = "";
Marc Kupietz03146622023-03-07 12:03:21 +0100118 $tmp_user->password = "***";
119 $tmp_user->user_hash = "***";
120 return json_encode($tmp_user);
121 }
122
123 function backup_in_session()
124 {
125 global $_SESSION;
126 foreach ($this as $key => $value) {
127 $_SESSION[$key] = $value;
128 }
129 }
130
131 function to_table() {
132 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
133 foreach ($this as $key => $value) {
Marc Kupietz49f677c2023-03-10 08:29:41 +0100134 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz03146622023-03-07 12:03:21 +0100135 if (is_bool($value)) {
136 if ($value) $value = "yes";
137 else $value = "no";
Marc Kupietz145f5b92023-03-09 20:39:31 +0100138 } elseif(is_float($value)) {
139 $key .= " €";
Marc Kupietz0215a442023-03-05 18:34:16 +0100140 }
Marc Kupietz03146622023-03-07 12:03:21 +0100141 $value = str_replace("\r\n", "<br>", $value);
142 $key = str_replace("_", " ", ucfirst($key));
143 $table .= " <tr>
144 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
145 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
146 </tr>\n";
147 }
Marc Kupietz0215a442023-03-05 18:34:16 +0100148 }
Marc Kupietz03146622023-03-07 12:03:21 +0100149 $table .= "</table>";
150 return $table;
151 }
152}