blob: aa7357c4e1aca3596213ff171409309e7adbecf6 [file] [log] [blame]
Marc Kupietzd871d882023-03-05 18:34:16 +01001<?php
2require_once 'vendor/autoload.php';
Marc Kupietz4f63f382023-03-15 09:13:03 +01003include_once 'utils.php';
Marc Kupietzd871d882023-03-05 18:34:16 +01004
5class User
6{
Marc Kupietzce676312023-03-10 08:29:41 +01007 public $id;
Marc Kupietz3417c882023-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 Kupietz2f3a4192023-03-09 08:14:12 +010022 public bool $author;
23 public $accepted_paper_id;
Marc Kupietz87a14312023-03-09 20:39:31 +010024 public bool $participation_confirmed;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010025 public $participation_confirmed_at;
26 public bool $student;
27 public bool $conference_dinner;
Marc Kupietzc8809a62023-03-21 17:58:11 +010028 public bool $vegetarian_dinner;
Marc Kupietzce676312023-03-10 08:29:41 +010029 public $registered_at;
30 public bool $earlybird_registration;
Marc Kupietz8701abd2023-03-16 17:33:43 +010031 public $lunch_day_1;
32 public $lunch_day_2;
33 public $lunch_day_3;
Marc Kupietz87a14312023-03-09 20:39:31 +010034 public float $total_due;
Marc Kupietzce676312023-03-10 08:29:41 +010035 public $invoice;
Marc Kupietz3417c882023-03-07 12:03:21 +010036
37 function __construct()
38 {
Marc Kupietzce676312023-03-10 08:29:41 +010039 $this->id = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010040 $this->username = "";
41 $this->first_name = "";
42 $this->last_name = "";
43 $this->email = "";
44 $this->organization = "";
45 $this->user_hash = "";
46 $this->password = "";
47 $this->city = "";
48 $this->country = "";
49 $this->zip = "";
50 $this->street = "";
51 $this->phone = "";
52 $this->eula_signed = false;
53 $this->privacy_policy_signed = false;
Marc Kupietz2f3a4192023-03-09 08:14:12 +010054 $this->author = false;
55 $this->accepted_paper_id = "";
56 $this->participation_confirmed = false;
57 $this->participation_confirmed_at = "";
58 $this->student = false;
59 $this->conference_dinner = false;
Marc Kupietzc8809a62023-03-21 17:58:11 +010060 $this->vegetarian_dinner = false;
Marc Kupietzce676312023-03-10 08:29:41 +010061 $this->registered_at = date("Y-m-d H:i:s") . "UTC";
62 $this->earlybird_registration = false;
Marc Kupietz87a14312023-03-09 20:39:31 +010063 $this->total_due = 0.0;
Marc Kupietzce676312023-03-10 08:29:41 +010064 $this->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +010065 }
66
67 function __construct1(object $data)
68 {
69 foreach ($data as $key => $value) {
70 if (array_key_exists($key, (array) $this))
71 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010072 }
Marc Kupietz3417c882023-03-07 12:03:21 +010073 if (isset($data->password)) $this->set_password($data->password);
74 }
Marc Kupietzd871d882023-03-05 18:34:16 +010075
Marc Kupietz3417c882023-03-07 12:03:21 +010076 function init_from_object(object $data)
77 {
78 foreach ($data as $key => $value) {
79 if (array_key_exists($key, (array) $this))
80 $this->{$key} = $value;
Marc Kupietza57befa2023-03-06 21:39:23 +010081 }
Marc Kupietz3417c882023-03-07 12:03:21 +010082 if (isset($data->password)) $this->set_password($data->password);
83 }
Marc Kupietza57befa2023-03-06 21:39:23 +010084
Marc Kupietz3417c882023-03-07 12:03:21 +010085 function init_from_array(array $data)
86 {
87 foreach ($data as $key => $value) {
88 if (array_key_exists($key, (array) $this)) {
89 if (is_bool(gettype($this->{$key})) && is_string($value))
90 $this->{$key} = !empty($value);
91 else
92 $this->{$key} = $value;
93 }
94 }
95 if (!empty($data["password"])) $this->set_password($data["password"]);
96 }
97
Marc Kupietz3417c882023-03-07 12:03:21 +010098
99 function set_password(string $password)
100 {
101 include 'config.php';
Marc Kupietz3b7170a2023-03-10 13:54:21 +0100102 if ($CONFERENCE_REGISTRATION) {
103 $this->password = generateRandomString(32);
Marc Kupietz3417c882023-03-07 12:03:21 +0100104 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
105 } else {
Marc Kupietz3b7170a2023-03-10 13:54:21 +0100106 if ($ENCRYPT_PASSWORDS) {
107 $this->user_hash = "{crypt}" . crypt($password, '$6$' . generateSalt(10) . '$');
108 # $this->user_hash = "{SHA}" . base64_encode(sha1($password, true));
109 } else {
110 $this->user_hash = "{CLEAR}" . $password;
111 }
112 $this->password = $this->user_hash;
Marc Kupietz3417c882023-03-07 12:03:21 +0100113 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100114 }
115
116 function to_string()
117 {
118 $tmp_user = $this;
Marc Kupietzce676312023-03-10 08:29:41 +0100119 $tmp_user->invoice = "";
Marc Kupietz3417c882023-03-07 12:03:21 +0100120 $tmp_user->password = "***";
121 $tmp_user->user_hash = "***";
122 return json_encode($tmp_user);
123 }
124
125 function backup_in_session()
126 {
127 global $_SESSION;
128 foreach ($this as $key => $value) {
129 $_SESSION[$key] = $value;
130 }
131 }
132
133 function to_table() {
134 $table = "<table style='border: 1px solid #e1e4e8; border-collapse: collapse; width: 100%;'>";
135 foreach ($this as $key => $value) {
Marc Kupietzce676312023-03-10 08:29:41 +0100136 if ($key != "password" && $key != "user_hash" && !empty($value) && $key != "invoice") {
Marc Kupietz3417c882023-03-07 12:03:21 +0100137 if (is_bool($value)) {
138 if ($value) $value = "yes";
139 else $value = "no";
Marc Kupietz87a14312023-03-09 20:39:31 +0100140 } elseif(is_float($value)) {
141 $key .= " €";
Marc Kupietz6557d442023-03-21 17:47:41 +0100142 $value = number_format($value, 2, '.', ' ');
Marc Kupietzd871d882023-03-05 18:34:16 +0100143 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100144 $value = str_replace("\r\n", "<br>", $value);
145 $key = str_replace("_", " ", ucfirst($key));
146 $table .= " <tr>
147 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'><strong>$key</strong></td>
148 <td style='border: 1px solid #e1e4e8; padding: 6px 13px;'>$value</td>
149 </tr>\n";
150 }
Marc Kupietzd871d882023-03-05 18:34:16 +0100151 }
Marc Kupietz3417c882023-03-07 12:03:21 +0100152 $table .= "</table>";
153 return $table;
154 }
155}